[Hibernate-devel] best practices doc

2002-07-19 Thread Gavin_King/Cirrus%CIRRUS
I'd like to throw this up for discussion. Anybody disagree with any of
these points or have any new ones?

==

*Hibernate ''Best'' Practices

***use fine grained objects
Write fine-grained classes and map them using || or
||. Use an |Address| class to encapsulate |street|,
|suburb|, |state|, |postcode|. This encourages code reuse and simplifies
refactoring.

***declare identifier properties on persistent classes
Hibernate makes identifier properties optional. There are all sorts of
reasons why you should use them. We recommend that identifiers be
'synthetic' (generated, with no business meaning) and of a non-primitive
type. For maximum flexibility, use |java.lang.Long| or |java.lang.String|.

***place each class mapping in its own file
Don't use a single monolithic mapping document. Map |com.eg.Foo| in the
file |com/eg/Foo.hbm.xml|.

***load mappings as resources
Deploy the mappings along with the classes they map.

***consider externalising query strings
This is a good practice if your queries call non-ANSI-standard SQL
functions. Externalising the query strings will make the application more
portable.

***use bind variables
As in JDBC, _always_ replace non-constant values by "?". Never use string
manipulation to bind a non-constant value in a query!

***don''t manage your own JDBC connections
Hibernate lets the application manage JDBC connections. This approach
should be considered a last-resort. If you can't use the built-in
connections providers, consider providing your own implementation of
|cirrus.hibernate.connection.ConnectionProvider|.

***consider using a custom type
Suppose you have a Java type, say from some library, that needs to be
persisted but doesn't provide the accessors needed to map it as a
component. You should consider implementing |cirrus.hibernate.UserType|.
This approach frees the application code from implementing transformations
to/from a Hibernate type.

***use hand-coded JDBC in bottlenecks
In performance-critical areas of the system, some kinds of operations (eg.
mass update/delete) might benefit from direct JDBC. But please, wait until
you _know_ something is a bottleneck. And don''t assume that direct JDBC is
_necessarily_ faster.

If need to use direct JDBC, it might be worth opening a Hibernate |Session|
and using that SQL connection. That way you can still use the same
transaction strategy and underlying connection provider.

***in a three tiered architecture, consider using |update()|
When using a servlet / session bean architecture, you could pass persistent
objects loaded in the session bean to and from the servlet / JSP layer. Use
a new session to service each request. Use |Session.update()| to update the
persistent state of an object.

***in a two tiered architecture, consider using session disconnection
When using a servlet only, you may reuse the same session for multiple
client requests. Just remember to disconnect the session before returning
control to the client.



---
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
___
Hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel



Re: [Hibernate-devel] best practices doc

2002-07-19 Thread Christian Bauer
On 19 Jul (11:25), Gavin_King/[EMAIL PROTECTED] wrote:

> I'd like to throw this up for discussion. Anybody disagree with any of
> these points or have any new ones?
> 
> ==
> 
> *Hibernate ''Best'' Practices

I agree with all of this practices and it is of course essential for a
beginner to know about this things.

I hope I will finish the DocBook transition today, how about an 
additional chapter "Best Practices"?  

-- 
Christian Bauer
[EMAIL PROTECTED]


---
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
___
Hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel



Re: [Hibernate-devel] best practices doc (1 class, 1 mapping xml)

2002-07-19 Thread Gavin_King/Cirrus%CIRRUS

>is there any technical advantage to this, or just the easthetic
>pleasure? :)

To me this is most important when developing in a team. Managing a
monolithic mapping file is very difficult if everyone is trying to
edit it at once. (But yeah, I do also find it improves the
aesthetics.)

>i was thinking i could help out w/ writing an xDoclet generator for the
>mapping file, so you can put the mapping directly in you class would
>that make sense?

Absolutely it would make sense :) Someone suggested this a few versions
ago but nothing ever came of it. I don't know much about xDoclet myself.

Gavin



---
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
___
Hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel



RE: [Hibernate-devel] JBoss MBean

2002-07-19 Thread Gavin_King/Cirrus%CIRRUS

> >>public void setProperties(String properties);<<
>
>Would this be properties that are normally placed in the
>hibernate.properties file?

yes, exactly. this would let you list the properties as
a comma-seperated list in the jcml file, and change them
dynamically from a management client.

Some of the properties are so important they warrant their
own attribute on the MBean, but not *all* of them...



---
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
___
Hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel



Re: [Hibernate-devel] Documentation in DocBook

2002-07-19 Thread Gavin_King/Cirrus%CIRRUS

>OK, I managed to get the basic conversion done right now. Have a look at
>the PDF version and a quick zip of the XML source files:
>
>http://incubus.de/~turin/hibernate_reference.pdf
>http://incubus.de/~turin/hibernate_reference_dbxml.tar.gz

Awesome! The PDF looks great. I'm so excited ;)

>- Move chapters and sections around for a more consistent read
>- Convert graphics to vector and make a small styleguide for this
>- Improve DSSSL stylesheet for PDF generation
>- Prepare stylesheets for HTML version
>- Add "Best Practices" chapter
>- Write makefiles and documentation for automatic output generation
>- Checkin to CVS

All good. I have the original diagrams as visio documents (lame, i
know) and I can send those if it would help at all.

>This will take some days, maybe I can checkin a version early next week.
>It's all not too difficult but time consuming stuff...

I know how time consuming it is - your work is very appreciated :)

Thanks

Gavin.



---
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
___
Hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel



[Hibernate-devel] Documentation in DocBook

2002-07-19 Thread Christian Bauer
On 19 Jul (18:30), Gavin_King/[EMAIL PROTECTED] wrote:

> Absolutely. If you can check in some example docbook stuff for me
> to work from, I will make this my chance to learn docbook
> 
> Looking forward to seeing the new doco Christian :)

OK, I managed to get the basic conversion done right now. Have a look at
the PDF version and a quick zip of the XML source files:

http://incubus.de/~turin/hibernate_reference.pdf
http://incubus.de/~turin/hibernate_reference_dbxml.tar.gz

To-Do:

- Move chapters and sections around for a more consistent read
- Convert graphics to vector and make a small styleguide for this
- Improve DSSSL stylesheet for PDF generation
- Prepare stylesheets for HTML version
- Add "Best Practices" chapter
- Write makefiles and documentation for automatic output generation
- Checkin to CVS

This will take some days, maybe I can checkin a version early next week.
It's all not too difficult but time consuming stuff...

-- 
Christian Bauer
[EMAIL PROTECTED]


---
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
___
Hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel