Update of /cvsroot/hibernate/Hibernate/doc In directory usw-pr-cvs1:/tmp/cvs-serv8871 Modified Files: faq.aft faq.aft-TOC faq.html links.aft links.html tools.aft tools.aft-TOC tools.html Log Message: various doco changes Index: faq.aft =================================================================== RCS file: /cvsroot/hibernate/Hibernate/doc/faq.aft,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** faq.aft 7 Nov 2002 16:24:07 -0000 1.27 --- faq.aft 10 Nov 2002 03:40:54 -0000 1.28 *************** *** 7,22 **** -------------------------------------------------------------------------- ! *** Hibernate expects my JDBC driver to support JDBC2 but it doesn't! ! ! Set ! ! hibernate.jdbc.batch_size=false ! hibernate.jdbc.use_scrollable_resultsets=false ! ! or upgrade your driver to the latest version. Hibernate chooses sensible default values for these properties, based upon your SQL dialect. ! ! *** My JDBC driver supports batch updates. How come Hibernate doesn't enable them by default? ! ! Batch updates seem to be cause problems for some JDBC drivers that claim to support them. We found that batch updates should be _disabled_ for DB2 and Sybase. *** I saved / deleted / updated an object / collection but I can't see the changes in the database! --- 7,11 ---- -------------------------------------------------------------------------- ! ** common problems for new users *** I saved / deleted / updated an object / collection but I can't see the changes in the database! *************** *** 51,58 **** --- 40,77 ---- Unlike other Hibernate value types, Hibernate tracks actual collection _instances_ using Java identity, |==|. Your getter method should return the same collection instance as was assigned by Hibernate to the setter method (unless you don't mind the collection being removed and recreated every time the session is flushed). + This doesn't mean you shouldn't return a different collection if you really _are_ replacing the current collection with a new collection with completely different elements. In certain cases, this behaviour can even be taken advantage of to increase performance. + + *** I removed an object from a collection mapped with cascade="all" but the object was not deleted ! + + |cascade="all"| cascades the |delete()| operation from parent to child. Hibernate _never_ deletes an entity without an explicit call to |delete()|. If you aren't deleting the parent object, you will have to explicitly delete the child. + + On the other hand, if you really want to avoid explicitly deleting collection elements, one solution is to model them as value types rather than entities. (Value types are always persisted or removed along with their parent entity.) So you would use a |<composite-element>| mapping for the element class instead of modelling it as a seperate entity. + + *** I'm confused about the semantics of saveOrUpdate() + + Firstly, so long as you are not trying to use instances from one session in another new session, you should not need to use |update()| or |saveOrUpdate()|. Some whole applications will never use either of these methods. + + Usually |update()| or |saveOrUpdate()| are used in the following scenario: + + 1. the application loads an object in the first session + 2. the object is passed up to the UI tier + 3. some modifications are made to the object + 4. the object is passed back down + 5. the application persists these modifications by calling |update()| in a second session + + |saveOrUpdate()| does the following: + + 1. if the object is already persistent in this session, do nothing + 2. if the object has no identifier property, |save()| it + 3. if the object's identifier matches the criteria specified by |unsaved-value|, |save()| it + 4. if another object associated with the session has the same identifier, throw an exception + 5. overwrite the existing state associated with the given object's identifier + *** How does readonly="true" affect the semantics of cascade="all" It doesn't. + ** more "advanced" problems + *** I'm using a composite identifier and Hibernate causes a stack overfow! *************** *** 65,68 **** --- 84,117 ---- And if you are using |<key-many-to-one>| you should compare entity equality by comparing identifiers instead of using |==|. + *** What column should I map the index tag of an array or List to? + + You need a seperate table column holding the array or List index (the |i| in |foo[i]|)! If your relational model doesn't have an index column, use a |Set| instead. This seems to put people off who assume that |List| should just be a more convenient way of accessing an unordered collection. Hibernate collections strictly obey the actual semantics attached to the |Set|, |List|, |Map| interfaces. |List| elements don't just spontaneously rearrange themselves. + + On the other hand, people who planned to use the |List| to emulate "bag"-style semantics have a legitimate grievance here. Fortunately you can map a |List| or |Collection| with bag semantics. + + *** What are bags for? + + A bag is an unordered, unindexed collection which can contain the same element multiple times. The Java collections framework lacks a |Bag| interface (though you can emulate it with a |List|). Hibernate lets you map properties of type |List| or |Collection| with the |<bag>| element. Note that bag semantics are not really part of the |Collection| contract and they actually conflict with the semantics of |List|. + + Large Hibernate bags are inefficient and should be avoided. (Hibernate can't create, delete or update rows individually.) + + *** I'm using a one-to-many association with a NOT NULL constraint on the key column and Hibernate causes constraint violations. + + Use a bidirectional association (mapping the many-valued end with |readonly="true"|). + + *** Hibernate is violating a unique constraint! + + Hibernate isn't quite as clever with unique constraints as it is with foreign keys. Sometimes you might need to give a little hint. + + A unique constraint violation could occur if two objects are both being updated, one is "releasing" a value and the other is "obtaining" the same value. A workaround is to |flush()| the session manually after updating the first object and before updating the second. + + (This kind of problem occurs rarely in practice.) + + *** I'm supplying my own connections to Hibernate and I see exceptions like: "too many opened cursors" + + You must disable |PreparedStatement| caching by setting + + hibernate.statement_cache.size=0 + *** My class has two one-to-many associations to different subclasses of the same root class, but Hibernate ignores the actual concrete class when loading the associations. *************** *** 93,96 **** --- 142,147 ---- 3. use a table-per-concrete-class mapping strategy for the |Transaction| hierarchy + ** tips and tricks + *** How can I count the number of query results without actually returning them? *************** *** 116,139 **** List page = q.list(); - *** How do I specify the length of a column for the SchemExport tool? A unique column? A not-null column? - - Column lengths and constraints may be specified in the mapping document. If you browse - - http://hibernate.sourceforge.net/hibernate-mapping.dtd - - you will find it quite well documented. - - *** What column should I map the index tag of an array or List to? - - You need a seperate table column holding the array or List index (the |i| in |foo[i]|)! If your relational model doesn't have an index column, use a |Set| instead. This seems to put people off who assume that |List| should just be a more convenient way of accessing an unordered collection. Hibernate collections strictly obey the actual semantics attached to the |Set|, |List|, |Map| interfaces. |List| elements don't just spontaneously rearrange themselves. - - On the other hand, people who planned to use the |List| to emulate "bag"-style semantics have a legitimate grievance here. Fortunately you can map a |List| or |Collection| with bag semantics. - - *** What are bags for? - - A bag is an unordered, unindexed collection which can contain the same element multiple times. The Java collections framework lacks a |Bag| interface (though you can emulate it with a |List|). Hibernate lets you map properties of type |List| or |Collection| with the |<bag>| element. Note that bag semantics are not really part of the |Collection| contract and they actually conflict with the semantics of |List|. - - Large Hibernate bags are inefficient and should be avoided. (Hibernate can't create, delete or update rows individually.) - *** I have a one-to-one association between two classes. Ensuring that associated objects have matching identifiers is bugprone. Is there a better way? --- 167,170 ---- *************** *** 182,228 **** </set> ! *** I removed an object from a collection mapped with cascade="all" but the object was not deleted ! ! ! |cascade="all"| cascades the |delete()| operation from parent to child. Hibernate _never_ deletes an entity without an explicit call to |delete()|. If you aren't deleting the parent object, you will have to explicitly delete the child. ! ! On the other hand, if you really want to avoid explicitly deleting collection elements, one solution is to model them as value types rather than entities. (Value types are always persisted or removed along with their parent entity.) So you would use a |<composite-element>| mapping for the element class instead of modelling it as a seperate entity. ! ! *** I'm confused about the semantics of saveOrUpdate() ! ! Firstly, so long as you are not trying to use instances from one session in another new session, you should not need to use |update()| or |saveOrUpdate()|. Some whole applications will never use either of these methods. ! ! Usually |update()| or |saveOrUpdate()| are used in the following scenario: ! ! 1. the application loads an object in the first session ! 2. the object is passed up to the UI tier ! 3. some modifications are made to the object ! 4. the object is passed back down ! 5. the application persists these modifications by calling |update()| in a second session ! ! |saveOrUpdate()| does the following: ! ! 1. if the object is already persistent in this session, do nothing ! 2. if the object has no identifier property, |save()| it ! 3. if the object's identifier matches the criteria specified by |unsaved-value|, |save()| it ! 4. if another object associated with the session has the same identifier, throw an exception ! 5. overwrite the existing state associated with the given object's identifier ! ! *** I'm using a one-to-many association with a NOT NULL constraint on the key column and Hibernate causes constraint violations. ! ! Use a bidirectional association (mapping the many-valued end with |readonly="true"|). ! ! *** Hibernate is violating a unique constraint! ! ! Hibernate isn't quite as clever with unique constraints as it is with foreign keys. Sometimes you might need to give a little hint. ! ! A unique constraint violation could occur if two objects are both being updated, one is "releasing" a value and the other is "obtaining" the same value. A workaround is to |flush()| the session manually after updating the first object and before updating the second. ! ! (This kind of problem occurs rarely in practice.) ! *** I'm supplying my own connections to Hibernate and I see exceptions like: "too many opened cursors" ! You must disable |PreparedStatement| caching by setting ! hibernate.statement_cache.size=0 *** I'm seeing ClassCastExceptions when I try to call Hibernate from inside JUnit. --- 213,223 ---- </set> ! *** In an MVC application, how can we ensure that all proxies and lazy collections will be initialized when the view tries to access them? ! One possible approach is to leave the session open (and transaction uncommitted) when forwarding to the view. The session / transaction would be closed / committed after the view is rendered in, for example, a servlet filter (another example would by to use the |ModelLifetime.discard()| callback in Maverick). One difficulty with this approach is making sure the session / transaction is closed / rolled back if an exception occurs rendering the view. ! Another approach is to simply force initialization of all needed objects using |Hibernate.initialize()|. This is often more straightforward than it sounds. ! ** testing *** I'm seeing ClassCastExceptions when I try to call Hibernate from inside JUnit. *************** *** 247,250 **** --- 242,263 ---- Another fix for this is to turn off class reloading in JUnit. + ** schema export + + *** How do I specify the length of a column for the SchemExport tool? A unique column? A not-null column? + + Column lengths and constraints may be specified in the mapping document. If you browse + + http://hibernate.sourceforge.net/hibernate-mapping-1.1.dtd + + you will find it quite well documented. + + *** I don't like the column type in the generated table creation script! + + You can customize the column type using the |<column>| element, eg. + + <property name="amount" type="big_decimal"> + <column sql-type="NUMERIC(11, 2)" not-null="true"/> + </property> + *** How can I embed table export functionality in my application? *************** *** 252,255 **** --- 265,325 ---- new cirrus.hibernate.tools.SchemaExport(ds, properties).create(false, true); + *** How can I export tables from an Ant script? + + Christoph Sturm reported that the following ant script successfully exported schema: + + <target name="initdb" depends="compile"> + <java classname="cirrus.hibernate.tools.SchemaExport" fork="true"> + <!-- mapping file --> + <arg value="/projects/smis/src/resources/web/WEB-INF/mapping.xml"/> + <jvmarg value="-Dhibernate.dialect=cirrus.hibernate.sql.SybaseDialect"/> + <jvmarg value="-Dhibernate.connection.driver_class=com.inet.tds.TdsDriver"/> + <jvmarg value="-Dhibernate.connection.url=jdbc:inetdae:localhost:1433"/> + <jvmarg value="-Dhibernate.connection.username=xxx"/> + <jvmarg value="-Dhibernate.connection.password=xxx"/> + <classpath> + <fileset dir="${basedir}/lib"> + <include name="**/*.jar" /> + </fileset> + <!-- build output path --> + <pathelement location="${build.dir}/classes/web/WEB-INF/classes"/> + </classpath> + </java> + </target> + + Jan Heise suggests the following: + + <fileset id="hibernate.mapping.files" dir="${dir.src}"> + <include name="**/*.hbm.xml" /> + </fileset> + + <target name="initdb" depends="prepare"> + <pathconvert refid="hibernate.mapping.files" property="hibernate.mappings" pathsep=" "/> + <java classname="cirrus.hibernate.tools.SchemaExport" fork="true"> + <arg line="${hibernate.mappings}"/> + <jvmarg value="-Dhibernate.dialect=cirrus.hibernate.sql.PostgreSQLDialect"/> + <jvmarg value="-Dhibernate.connection.driver_class=org.postgresql.Driver"/> + <jvmarg value="-Dhibernate.connection.url=jdbc:postgresql://xxxxx/xxxx"/> + <jvmarg value="-Dhibernate.connection.username=xxxx"/> + <jvmarg value="-Dhibernate.connection.password=xxxx"/> + <classpath refid="project.class.path" /> + </java> + </target> + + <target name="dropdb" depends="prepare"> + <pathconvert refid="hibernate.mapping.files" property="hibernate.mappings" pathsep=" "/> + <java classname="cirrus.hibernate.tools.SchemaExport" fork="true"> + <arg line="${hibernate.mappings}"/> + <jvmarg value="-Dhibernate.dialect=cirrus.hibernate.sql.PostgreSQLDialect"/> + <jvmarg value="-Dhibernate.connection.driver_class=org.postgresql.Driver"/> + <jvmarg value="-Dhibernate.connection.url=jdbc:postgresql://xxxxx/xxxx"/> + <jvmarg value="-Dhibernate.connection.username=xxxx"/> + <jvmarg value="-Dhibernate.connection.password=xxxx"/> + <classpath refid="project.class.path" /> + </java> + </target> + + ** configuration + *** Whats the easiest way to configure Hibernate in a plain Java application (without using JNDI)? *************** *** 298,302 **** *** How do I configure the cache? ! Hibernate uses JCS for its factory-level caching. JCS is configured by placing a properties file named cache.ccf in the classpath. See http://jakarta.apache.org/turbine/jcs/ --- 368,372 ---- *** How do I configure the cache? ! Hibernate uses JCS for its factory-level caching. JCS is configured by placing a properties file named |cache.ccf| in the classpath. See http://jakarta.apache.org/turbine/jcs/ *************** *** 304,307 **** --- 374,392 ---- Don't use a JCS distributed cache with |usage="read-write"|. (In fact, you shouldn't be using a |read-write| cache in a multiserver environment anyway.) + ** platform specific issues + + *** Hibernate expects my JDBC driver to support JDBC2 but it doesn't! + + Set + + hibernate.jdbc.batch_size=false + hibernate.jdbc.use_scrollable_resultsets=false + + or upgrade your driver to the latest version. Hibernate chooses sensible default values for these properties, based upon your SQL dialect. + + *** My JDBC driver supports batch updates. How come Hibernate doesn't enable them by default? + + Batch updates seem to be cause problems for some JDBC drivers that claim to support them. We found that batch updates should be _disabled_ for DB2 and Sybase. + *** Why is Microsoft's own JDBC driver for SQL server not supported? *************** *** 319,329 **** * If you are altering tables you should be in single user mode. This can be achieved by running |gfix -shut|. It's also sufficient to have only one database connection open (eg. immediately after starting the application). If more than one connection is open, you will see errors like "table is in use". To restart your database use |gfix -online|. ! *** I don't like the column type in the generated table creation script! ! ! You can customize the column type using the |<column>| element, eg. ! ! <property name="amount" type="big_decimal"> ! <column sql-type="NUMERIC(11, 2)" not-null="true"/> ! </property> *** Where can I get more help? --- 404,408 ---- * If you are altering tables you should be in single user mode. This can be achieved by running |gfix -shut|. It's also sufficient to have only one database connection open (eg. immediately after starting the application). If more than one connection is open, you will see errors like "table is in use". To restart your database use |gfix -online|. ! ** miscellaneous *** Where can I get more help? Index: faq.aft-TOC =================================================================== RCS file: /cvsroot/hibernate/Hibernate/doc/faq.aft-TOC,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** faq.aft-TOC 7 Nov 2002 16:24:07 -0000 1.18 --- faq.aft-TOC 10 Nov 2002 03:40:54 -0000 1.19 *************** *** 1,5 **** C--- AFT Table of Contents (auto generated) ! * {-Hibernate expects my JDBC driver to support JDBC2 but it doesn't!@Hibernate expects my JDBC driver to support JDBC2 but it doesn't!-} ! * {-My JDBC driver supports batch updates. How come Hibernate doesn't enable them by default?@My JDBC driver supports batch updates. How come Hibernate doesn't enable them by default?-} * {-I saved / deleted / updated an object / collection but I can't see the changes in the database!@I saved / deleted / updated an object / collection but I can't see the changes in the database!-} * {-I saved a parent object but its associated objects weren't saved to the database@I saved a parent object but its associated objects weren't saved to the database-} --- 1,4 ---- C--- AFT Table of Contents (auto generated) ! * {-common problems for new users@common problems for new users-} * {-I saved / deleted / updated an object / collection but I can't see the changes in the database!@I saved / deleted / updated an object / collection but I can't see the changes in the database!-} * {-I saved a parent object but its associated objects weren't saved to the database@I saved a parent object but its associated objects weren't saved to the database-} *************** *** 8,31 **** * {-I have some other kind of wierd bugs.....@I have some other kind of wierd bugs.....-} * {-Hibernate keeps deleting and recreating my collection!@Hibernate keeps deleting and recreating my collection!-} * {-How does readonly="true" affect the semantics of cascade="all"@How does readonly="true" affect the semantics of cascade="all"-} * {-I'm using a composite identifier and Hibernate causes a stack overfow!@I'm using a composite identifier and Hibernate causes a stack overfow!-} * {-I'm seeing some strange behaviour with an embedded composite identifier or <key-many-to-one> when using proxies.@I'm seeing some strange behaviour with an embedded composite identifier or <key-many-to-one> when using proxies.-} * {-My class has two one-to-many associations to different subclasses of the same root class, but Hibernate ignores the actual concrete class when loading the associations.@My class has two one-to-many associations to different subclasses of the same root class, but Hibernate ignores the actual concrete class when loading the associations.-} * {-How can I count the number of query results without actually returning them?@How can I count the number of query results without actually returning them?-} * {-How can I find the size of a collection without initializing it?@How can I find the size of a collection without initializing it?-} * {-How can I sort / order collection elements?@How can I sort / order collection elements?-} * {-Are collections pageable?@Are collections pageable?-} - * {-How do I specify the length of a column for the SchemExport tool? A unique column? A not-null column?@How do I specify the length of a column for the SchemExport tool? A unique column? A not-null column?-} - * {-What column should I map the index tag of an array or List to?@What column should I map the index tag of an array or List to?-} - * {-What are bags for?@What are bags for?-} * {-I have a one-to-one association between two classes. Ensuring that associated objects have matching identifiers is bugprone. Is there a better way?@I have a one-to-one association between two classes. Ensuring that associated objects have matching identifiers is bugprone. Is there a better way?-} * {-I have a many-to-many association between two tables, but the association table has some extra columns (apart from the foreign keys). What kind of mapping should I use?@I have a many-to-many association between two tables, but the association table has some extra columns (apart from the foreign keys). What kind of mapping should I use?-} ! * {-I removed an object from a collection mapped with cascade="all" but the object was not deleted !@I removed an object from a collection mapped with cascade="all" but the object was not deleted !-} ! * {-I'm confused about the semantics of saveOrUpdate()@I'm confused about the semantics of saveOrUpdate()-} ! * {-I'm using a one-to-many association with a NOT NULL constraint on the key column and Hibernate causes constraint violations.@I'm using a one-to-many association with a NOT NULL constraint on the key column and Hibernate causes constraint violations.-} ! * {-Hibernate is violating a unique constraint!@Hibernate is violating a unique constraint!-} ! * {-I'm supplying my own connections to Hibernate and I see exceptions like: "too many opened cursors"@I'm supplying my own connections to Hibernate and I see exceptions like: "too many opened cursors"-} * {-I'm seeing ClassCastExceptions when I try to call Hibernate from inside JUnit.@I'm seeing ClassCastExceptions when I try to call Hibernate from inside JUnit.-} * {-How can I embed table export functionality in my application?@How can I embed table export functionality in my application?-} * {-Whats the easiest way to configure Hibernate in a plain Java application (without using JNDI)?@Whats the easiest way to configure Hibernate in a plain Java application (without using JNDI)?-} * {-Whats the easiest way to configure Hibernate in a J2EE application (using JNDI)?@Whats the easiest way to configure Hibernate in a J2EE application (using JNDI)?-} --- 7,38 ---- * {-I have some other kind of wierd bugs.....@I have some other kind of wierd bugs.....-} * {-Hibernate keeps deleting and recreating my collection!@Hibernate keeps deleting and recreating my collection!-} + * {-I removed an object from a collection mapped with cascade="all" but the object was not deleted !@I removed an object from a collection mapped with cascade="all" but the object was not deleted !-} + * {-I'm confused about the semantics of saveOrUpdate()@I'm confused about the semantics of saveOrUpdate()-} * {-How does readonly="true" affect the semantics of cascade="all"@How does readonly="true" affect the semantics of cascade="all"-} + * {-more "advanced" problems@more "advanced" problems-} * {-I'm using a composite identifier and Hibernate causes a stack overfow!@I'm using a composite identifier and Hibernate causes a stack overfow!-} * {-I'm seeing some strange behaviour with an embedded composite identifier or <key-many-to-one> when using proxies.@I'm seeing some strange behaviour with an embedded composite identifier or <key-many-to-one> when using proxies.-} + * {-What column should I map the index tag of an array or List to?@What column should I map the index tag of an array or List to?-} + * {-What are bags for?@What are bags for?-} + * {-I'm using a one-to-many association with a NOT NULL constraint on the key column and Hibernate causes constraint violations.@I'm using a one-to-many association with a NOT NULL constraint on the key column and Hibernate causes constraint violations.-} + * {-Hibernate is violating a unique constraint!@Hibernate is violating a unique constraint!-} + * {-I'm supplying my own connections to Hibernate and I see exceptions like: "too many opened cursors"@I'm supplying my own connections to Hibernate and I see exceptions like: "too many opened cursors"-} * {-My class has two one-to-many associations to different subclasses of the same root class, but Hibernate ignores the actual concrete class when loading the associations.@My class has two one-to-many associations to different subclasses of the same root class, but Hibernate ignores the actual concrete class when loading the associations.-} + * {-tips and tricks@tips and tricks-} * {-How can I count the number of query results without actually returning them?@How can I count the number of query results without actually returning them?-} * {-How can I find the size of a collection without initializing it?@How can I find the size of a collection without initializing it?-} * {-How can I sort / order collection elements?@How can I sort / order collection elements?-} * {-Are collections pageable?@Are collections pageable?-} * {-I have a one-to-one association between two classes. Ensuring that associated objects have matching identifiers is bugprone. Is there a better way?@I have a one-to-one association between two classes. Ensuring that associated objects have matching identifiers is bugprone. Is there a better way?-} * {-I have a many-to-many association between two tables, but the association table has some extra columns (apart from the foreign keys). What kind of mapping should I use?@I have a many-to-many association between two tables, but the association table has some extra columns (apart from the foreign keys). What kind of mapping should I use?-} ! * {-In an MVC application, how can we ensure that all proxies and lazy collections will be initialized when the view tries to access them?@In an MVC application, how can we ensure that all proxies and lazy collections will be initialized when the view tries to access them?-} ! * {-testing@testing-} * {-I'm seeing ClassCastExceptions when I try to call Hibernate from inside JUnit.@I'm seeing ClassCastExceptions when I try to call Hibernate from inside JUnit.-} + * {-schema export@schema export-} + * {-How do I specify the length of a column for the SchemExport tool? A unique column? A not-null column?@How do I specify the length of a column for the SchemExport tool? A unique column? A not-null column?-} + * {-I don't like the column type in the generated table creation script!@I don't like the column type in the generated table creation script!-} * {-How can I embed table export functionality in my application?@How can I embed table export functionality in my application?-} + * {-How can I export tables from an Ant script?@How can I export tables from an Ant script?-} + * {-configuration@configuration-} * {-Whats the easiest way to configure Hibernate in a plain Java application (without using JNDI)?@Whats the easiest way to configure Hibernate in a plain Java application (without using JNDI)?-} * {-Whats the easiest way to configure Hibernate in a J2EE application (using JNDI)?@Whats the easiest way to configure Hibernate in a J2EE application (using JNDI)?-} *************** *** 34,39 **** * {-How do I configure logging?@How do I configure logging?-} * {-How do I configure the cache?@How do I configure the cache?-} * {-Why is Microsoft's own JDBC driver for SQL server not supported?@Why is Microsoft's own JDBC driver for SQL server not supported?-} * {-Are there known issues with Interbase / Firebird?@Are there known issues with Interbase / Firebird?-} ! * {-I don't like the column type in the generated table creation script!@I don't like the column type in the generated table creation script!-} * {-Where can I get more help?@Where can I get more help?-} --- 41,49 ---- * {-How do I configure logging?@How do I configure logging?-} * {-How do I configure the cache?@How do I configure the cache?-} + * {-platform specific issues@platform specific issues-} + * {-Hibernate expects my JDBC driver to support JDBC2 but it doesn't!@Hibernate expects my JDBC driver to support JDBC2 but it doesn't!-} + * {-My JDBC driver supports batch updates. How come Hibernate doesn't enable them by default?@My JDBC driver supports batch updates. How come Hibernate doesn't enable them by default?-} * {-Why is Microsoft's own JDBC driver for SQL server not supported?@Why is Microsoft's own JDBC driver for SQL server not supported?-} * {-Are there known issues with Interbase / Firebird?@Are there known issues with Interbase / Firebird?-} ! * {-miscellaneous@miscellaneous-} * {-Where can I get more help?@Where can I get more help?-} Index: faq.html =================================================================== RCS file: /cvsroot/hibernate/Hibernate/doc/faq.html,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** faq.html 7 Nov 2002 16:24:08 -0000 1.40 --- faq.html 10 Nov 2002 03:40:54 -0000 1.41 *************** *** 20,26 **** <ul> <ul> <ul> - <li> <a href="#Hibernate expects my JDBC driver to support JDBC2 but it doesn't!">Hibernate expects my JDBC driver to support JDBC2 but it doesn't!</a></li> - <li> <a href="#My JDBC driver supports batch updates. How come Hibernate doesn't enable them by default?">My JDBC driver supports batch updates. How come Hibernate doesn't enable them by default?</a></li> <li> <a href="#I saved / deleted / updated an object / collection but I can't see the changes in the database!">I saved / deleted / updated an object / collection but I can't see the changes in the database!</a></li> <li> <a href="#I saved a parent object but its associated objects weren't saved to the database">I saved a parent object but its associated objects weren't saved to the database</a></li> --- 20,25 ---- <ul> <ul> + <li> <a href="#common problems for new users">common problems for new users</a></li> <ul> <li> <a href="#I saved / deleted / updated an object / collection but I can't see the changes in the database!">I saved / deleted / updated an object / collection but I can't see the changes in the database!</a></li> <li> <a href="#I saved a parent object but its associated objects weren't saved to the database">I saved a parent object but its associated objects weren't saved to the database</a></li> *************** *** 29,52 **** <li> <a href="#I have some other kind of wierd bugs.....">I have some other kind of wierd bugs.....</a></li> <li> <a href="#Hibernate keeps deleting and recreating my collection!">Hibernate keeps deleting and recreating my collection!</a></li> <li> <a href="#How does readonly="true" affect the semantics of cascade="all"">How does readonly="true" affect the semantics of cascade="all"</a></li> <li> <a href="#I'm using a composite identifier and Hibernate causes a stack overfow!">I'm using a composite identifier and Hibernate causes a stack overfow!</a></li> <li> <a href="#I'm seeing some strange behaviour with an embedded composite identifier or <key-many-to-one> when using proxies.">I'm seeing some strange behaviour with an embedded composite identifier or <key-many-to-one> when using proxies.</a></li> <li> <a href="#My class has two one-to-many associations to different subclasses of the same root class, but Hibernate ignores the actual concrete class when loading the associations.">My class has two one-to-many associations to different subclasses of the same root class, but Hibernate ignores the actual concrete class when loading the associations.</a></li> <li> <a href="#How can I count the number of query results without actually returning them?">How can I count the number of query results without actually returning them?</a></li> <li> <a href="#How can I find the size of a collection without initializing it?">How can I find the size of a collection without initializing it?</a></li> <li> <a href="#How can I sort / order collection elements?">How can I sort / order collection elements?</a></li> <li> <a href="#Are collections pageable?">Are collections pageable?</a></li> - <li> <a href="#How do I specify the length of a column for the SchemExport tool? A unique column? A not-null column?">How do I specify the length of a column for the SchemExport tool? A unique column? A not-null column?</a></li> - <li> <a href="#What column should I map the index tag of an array or List to?">What column should I map the index tag of an array or List to?</a></li> - <li> <a href="#What are bags for?">What are bags for?</a></li> <li> <a href="#I have a one-to-one association between two classes. Ensuring that associated objects have matching identifiers is bugprone. Is there a better way?">I have a one-to-one association between two classes. Ensuring that associated objects have matching identifiers is bugprone. Is there a better way?</a></li> <li> <a href="#I have a many-to-many association between two tables, but the association table has some extra columns (apart from the foreign keys). What kind of mapping should I use?">I have a many-to-many association between two tables, but the association table has some extra columns (apart from the foreign keys). What kind of mapping should I use?</a></li> ! <li> <a href="#I removed an object from a collection mapped with cascade="all" but the object was not deleted !">I removed an object from a collection mapped with cascade="all" but the object was not deleted !</a></li> ! <li> <a href="#I'm confused about the semantics of saveOrUpdate()">I'm confused about the semantics of saveOrUpdate()</a></li> ! <li> <a href="#I'm using a one-to-many association with a NOT NULL constraint on the key column and Hibernate causes constraint violations.">I'm using a one-to-many association with a NOT NULL constraint on the key column and Hibernate causes constraint violations.</a></li> ! <li> <a href="#Hibernate is violating a unique constraint!">Hibernate is violating a unique constraint!</a></li> ! <li> <a href="#I'm supplying my own connections to Hibernate and I see exceptions like: "too many opened cursors"">I'm supplying my own connections to Hibernate and I see exceptions like: "too many opened cursors"</a></li> <li> <a href="#I'm seeing ClassCastExceptions when I try to call Hibernate from inside JUnit.">I'm seeing ClassCastExceptions when I try to call Hibernate from inside JUnit.</a></li> <li> <a href="#How can I embed table export functionality in my application?">How can I embed table export functionality in my application?</a></li> <li> <a href="#Whats the easiest way to configure Hibernate in a plain Java application (without using JNDI)?">Whats the easiest way to configure Hibernate in a plain Java application (without using JNDI)?</a></li> <li> <a href="#Whats the easiest way to configure Hibernate in a J2EE application (using JNDI)?">Whats the easiest way to configure Hibernate in a J2EE application (using JNDI)?</a></li> --- 28,69 ---- <li> <a href="#I have some other kind of wierd bugs.....">I have some other kind of wierd bugs.....</a></li> <li> <a href="#Hibernate keeps deleting and recreating my collection!">Hibernate keeps deleting and recreating my collection!</a></li> + <li> <a href="#I removed an object from a collection mapped with cascade="all" but the object was not deleted !">I removed an object from a collection mapped with cascade="all" but the object was not deleted !</a></li> + <li> <a href="#I'm confused about the semantics of saveOrUpdate()">I'm confused about the semantics of saveOrUpdate()</a></li> <li> <a href="#How does readonly="true" affect the semantics of cascade="all"">How does readonly="true" affect the semantics of cascade="all"</a></li> + </ul> + <li> <a href="#more "advanced" problems">more "advanced" problems</a></li> + <ul> <li> <a href="#I'm using a composite identifier and Hibernate causes a stack overfow!">I'm using a composite identifier and Hibernate causes a stack overfow!</a></li> <li> <a href="#I'm seeing some strange behaviour with an embedded composite identifier or <key-many-to-one> when using proxies.">I'm seeing some strange behaviour with an embedded composite identifier or <key-many-to-one> when using proxies.</a></li> + <li> <a href="#What column should I map the index tag of an array or List to?">What column should I map the index tag of an array or List to?</a></li> + <li> <a href="#What are bags for?">What are bags for?</a></li> + <li> <a href="#I'm using a one-to-many association with a NOT NULL constraint on the key column and Hibernate causes constraint violations.">I'm using a one-to-many association with a NOT NULL constraint on the key column and Hibernate causes constraint violations.</a></li> + <li> <a href="#Hibernate is violating a unique constraint!">Hibernate is violating a unique constraint!</a></li> + <li> <a href="#I'm supplying my own connections to Hibernate and I see exceptions like: "too many opened cursors"">I'm supplying my own connections to Hibernate and I see exceptions like: "too many opened cursors"</a></li> <li> <a href="#My class has two one-to-many associations to different subclasses of the same root class, but Hibernate ignores the actual concrete class when loading the associations.">My class has two one-to-many associations to different subclasses of the same root class, but Hibernate ignores the actual concrete class when loading the associations.</a></li> + </ul> + <li> <a href="#tips and tricks">tips and tricks</a></li> + <ul> <li> <a href="#How can I count the number of query results without actually returning them?">How can I count the number of query results without actually returning them?</a></li> <li> <a href="#How can I find the size of a collection without initializing it?">How can I find the size of a collection without initializing it?</a></li> <li> <a href="#How can I sort / order collection elements?">How can I sort / order collection elements?</a></li> <li> <a href="#Are collections pageable?">Are collections pageable?</a></li> <li> <a href="#I have a one-to-one association between two classes. Ensuring that associated objects have matching identifiers is bugprone. Is there a better way?">I have a one-to-one association between two classes. Ensuring that associated objects have matching identifiers is bugprone. Is there a better way?</a></li> <li> <a href="#I have a many-to-many association between two tables, but the association table has some extra columns (apart from the foreign keys). What kind of mapping should I use?">I have a many-to-many association between two tables, but the association table has some extra columns (apart from the foreign keys). What kind of mapping should I use?</a></li> ! <li> <a href="#In an MVC application, how can we ensure that all proxies and lazy collections will be initialized when the view tries to access them?">In an MVC application, how can we ensure that all proxies and lazy collections will be initialized when the view tries to access them?</a></li> ! </ul> ! <li> <a href="#testing">testing</a></li> ! <ul> <li> <a href="#I'm seeing ClassCastExceptions when I try to call Hibernate from inside JUnit.">I'm seeing ClassCastExceptions when I try to call Hibernate from inside JUnit.</a></li> + </ul> + <li> <a href="#schema export">schema export</a></li> + <ul> + <li> <a href="#How do I specify the length of a column for the SchemExport tool? A unique column? A not-null column?">How do I specify the length of a column for the SchemExport tool? A unique column? A not-null column?</a></li> + <li> <a href="#I don't like the column type in the generated table creation script!">I don't like the column type in the generated table creation script!</a></li> <li> <a href="#How can I embed table export functionality in my application?">How can I embed table export functionality in my application?</a></li> + <li> <a href="#How can I export tables from an Ant script?">How can I export tables from an Ant script?</a></li> + </ul> + <li> <a href="#configuration">configuration</a></li> + <ul> <li> <a href="#Whats the easiest way to configure Hibernate in a plain Java application (without using JNDI)?">Whats the easiest way to configure Hibernate in a plain Java application (without using JNDI)?</a></li> <li> <a href="#Whats the easiest way to configure Hibernate in a J2EE application (using JNDI)?">Whats the easiest way to configure Hibernate in a J2EE application (using JNDI)?</a></li> *************** *** 55,61 **** <li> <a href="#How do I configure logging?">How do I configure logging?</a></li> <li> <a href="#How do I configure the cache?">How do I configure the cache?</a></li> <li> <a href="#Why is Microsoft's own JDBC driver for SQL server not supported?">Why is Microsoft's own JDBC driver for SQL server not supported?</a></li> <li> <a href="#Are there known issues with Interbase / Firebird?">Are there known issues with Interbase / Firebird?</a></li> ! <li> <a href="#I don't like the column type in the generated table creation script!">I don't like the column type in the generated table creation script!</a></li> <li> <a href="#Where can I get more help?">Where can I get more help?</a> --- 72,85 ---- <li> <a href="#How do I configure logging?">How do I configure logging?</a></li> <li> <a href="#How do I configure the cache?">How do I configure the cache?</a></li> + </ul> + <li> <a href="#platform specific issues">platform specific issues</a></li> + <ul> + <li> <a href="#Hibernate expects my JDBC driver to support JDBC2 but it doesn't!">Hibernate expects my JDBC driver to support JDBC2 but it doesn't!</a></li> + <li> <a href="#My JDBC driver supports batch updates. How come Hibernate doesn't enable them by default?">My JDBC driver supports batch updates. How come Hibernate doesn't enable them by default?</a></li> <li> <a href="#Why is Microsoft's own JDBC driver for SQL server not supported?">Why is Microsoft's own JDBC driver for SQL server not supported?</a></li> <li> <a href="#Are there known issues with Interbase / Firebird?">Are there known issues with Interbase / Firebird?</a></li> ! </ul> ! <li> <a href="#miscellaneous">miscellaneous</a></li> ! <ul> <li> <a href="#Where can I get more help?">Where can I get more help?</a> *************** *** 65,86 **** </ul> <hr> <!-- Start SectLevel3 --> - <h4><a name="Hibernate expects my JDBC driver to support JDBC2 but it doesn't!">Hibernate expects my JDBC driver to support JDBC2 but it doesn't!</a></h4> - <p class="Body"> - Set - </p> - <pre> - hibernate.jdbc.batch_size=false - hibernate.jdbc.use_scrollable_resultsets=false - </pre> - <p class="Body"> - or upgrade your driver to the latest version. Hibernate chooses sensible default values for these properties, based upon your SQL dialect. - </p> - <!--End Section 3--> - <h4><a name="My JDBC driver supports batch updates. How come Hibernate doesn't enable them by default?">My JDBC driver supports batch updates. How come Hibernate doesn't enable them by default?</a></h4> - <p class="Body"> - Batch updates seem to be cause problems for some JDBC drivers that claim to support them. We found that batch updates should be <strong>disabled</strong> for DB2 and Sybase. - </p> - <!--End Section 3--> <h4><a name="I saved / deleted / updated an object / collection but I can't see the changes in the database!">I saved / deleted / updated an object / collection but I can't see the changes in the database!</a></h4> <p class="Body"> --- 89,95 ---- </ul> <hr> + <!-- Start SectLevel2 --> + <h3><a name="common problems for new users">common problems for new users</a></h3> <!-- Start SectLevel3 --> <h4><a name="I saved / deleted / updated an object / collection but I can't see the changes in the database!">I saved / deleted / updated an object / collection but I can't see the changes in the database!</a></h4> <p class="Body"> *************** *** 122,125 **** --- 131,170 ---- Unlike other Hibernate value types, Hibernate tracks actual collection <strong>instances</strong> using Java identity, <tt>==</tt>. Your getter method should return the same collection instance as was assigned by Hibernate to the setter method (unless you don't mind the collection being removed and recreated every time the session is flushed). </p> + <p class="Body"> + This doesn't mean you shouldn't return a different collection if you really <strong>are</strong> replacing the current collection with a new collection with completely different elements. In certain cases, this behaviour can even be taken advantage of to increase performance. + </p> + <!--End Section 3--> + <h4><a name="I removed an object from a collection mapped with cascade="all" but the object was not deleted !">I removed an object from a collection mapped with cascade="all" but the object was not deleted !</a></h4> + <p class="Body"> + <tt>cascade="all"</tt> cascades the <tt>delete()</tt> operation from parent to child. Hibernate <strong>never</strong> deletes an entity without an explicit call to <tt>delete()</tt>. If you aren't deleting the parent object, you will have to explicitly delete the child. + </p> + <p class="Body"> + On the other hand, if you really want to avoid explicitly deleting collection elements, one solution is to model them as value types rather than entities. (Value types are always persisted or removed along with their parent entity.) So you would use a <tt><composite-element></tt> mapping for the element class instead of modelling it as a seperate entity. + </p> + <!--End Section 3--> + <h4><a name="I'm confused about the semantics of saveOrUpdate()">I'm confused about the semantics of saveOrUpdate()</a></h4> + <p class="Body"> + Firstly, so long as you are not trying to use instances from one session in another new session, you should not need to use <tt>update()</tt> or <tt>saveOrUpdate()</tt>. Some whole applications will never use either of these methods. + </p> + <p class="Body"> + Usually <tt>update()</tt> or <tt>saveOrUpdate()</tt> are used in the following scenario: + </p> + <ol> + <li> the application loads an object in the first session</li> + <li> the object is passed up to the UI tier</li> + <li> some modifications are made to the object</li> + <li> the object is passed back down</li> + <li> the application persists these modifications by calling <tt>update()</tt> in a second session</li> + </ol> + <p class="Body"> + <tt>saveOrUpdate()</tt> does the following: + </p> + <ol> + <li> if the object is already persistent in this session, do nothing</li> + <li> if the object has no identifier property, <tt>save()</tt> it</li> + <li> if the object's identifier matches the criteria specified by <tt>unsaved-value</tt>, <tt>save()</tt> it</li> + <li> if another object associated with the session has the same identifier, throw an exception </li> + <li> overwrite the existing state associated with the given object's identifier</li> + </ol> <!--End Section 3--> <h4><a name="How does readonly="true" affect the semantics of cascade="all"">How does readonly="true" affect the semantics of cascade="all"</a></h4> *************** *** 128,131 **** --- 173,180 ---- </p> <!--End Section 3--> + <!-- End SectLevel3 --> + <!--End Section 2--> + <h3><a name="more "advanced" problems">more "advanced" problems</a></h3> + <!-- Start SectLevel3 --> <h4><a name="I'm using a composite identifier and Hibernate causes a stack overfow!">I'm using a composite identifier and Hibernate causes a stack overfow!</a></h4> <p class="Body"> *************** *** 141,144 **** --- 190,233 ---- </p> <!--End Section 3--> + <h4><a name="What column should I map the index tag of an array or List to?">What column should I map the index tag of an array or List to?</a></h4> + <p class="Body"> + You need a seperate table column holding the array or List index (the <tt>i</tt> in <tt>foo[i]</tt>)! If your relational model doesn't have an index column, use a <tt>Set</tt> instead. This seems to put people off who assume that <tt>List</tt> should just be a more convenient way of accessing an unordered collection. Hibernate collections strictly obey the actual semantics attached to the <tt>Set</tt>, <tt>List</tt>, <tt>Map</tt> interfaces. <tt>List</tt> elements don't just spontaneously rearrange themselves. + </p> + <p class="Body"> + On the other hand, people who planned to use the <tt>List</tt> to emulate "bag"-style semantics have a legitimate grievance here. Fortunately you can map a <tt>List</tt> or <tt>Collection</tt> with bag semantics. + </p> + <!--End Section 3--> + <h4><a name="What are bags for?">What are bags for?</a></h4> + <p class="Body"> + A bag is an unordered, unindexed collection which can contain the same element multiple times. The Java collections framework lacks a <tt>Bag</tt> interface (though you can emulate it with a <tt>List</tt>). Hibernate lets you map properties of type <tt>List</tt> or <tt>Collection</tt> with the <tt><bag></tt> element. Note that bag semantics are not really part of the <tt>Collection</tt> contract and they actually conflict with the semantics of <tt>List</tt>. + </p> + <p class="Body"> + Large Hibernate bags are inefficient and should be avoided. (Hibernate can't create, delete or update rows individually.) + </p> + <!--End Section 3--> + <h4><a name="I'm using a one-to-many association with a NOT NULL constraint on the key column and Hibernate causes constraint violations.">I'm using a one-to-many association with a NOT NULL constraint on the key column and Hibernate causes constraint violations.</a></h4> + <p class="Body"> + Use a bidirectional association (mapping the many-valued end with <tt>readonly="true"</tt>). + </p> + <!--End Section 3--> + <h4><a name="Hibernate is violating a unique constraint!">Hibernate is violating a unique constraint!</a></h4> + <p class="Body"> + Hibernate isn't quite as clever with unique constraints as it is with foreign keys. Sometimes you might need to give a little hint. + </p> + <p class="Body"> + A unique constraint violation could occur if two objects are both being updated, one is "releasing" a value and the other is "obtaining" the same value. A workaround is to <tt>flush()</tt> the session manually after updating the first object and before updating the second. + </p> + <p class="Body"> + (This kind of problem occurs rarely in practice.) + </p> + <!--End Section 3--> + <h4><a name="I'm supplying my own connections to Hibernate and I see exceptions like: "too many opened cursors"">I'm supplying my own connections to Hibernate and I see exceptions like: "too many opened cursors"</a></h4> + <p class="Body"> + You must disable <tt>PreparedStatement</tt> caching by setting + </p> + <pre> + hibernate.statement_cache.size=0 + </pre> + <!--End Section 3--> <h4><a name="My class has two one-to-many associations to different subclasses of the same root class, but Hibernate ignores the actual concrete class when loading the associations.">My class has two one-to-many associations to different subclasses of the same root class, but Hibernate ignores the actual concrete class when loading the associations.</a></h4> <p class="Body"> *************** *** 174,177 **** --- 263,270 ---- </ol> <!--End Section 3--> + <!-- End SectLevel3 --> + <!--End Section 2--> + <h3><a name="tips and tricks">tips and tricks</a></h3> + <!-- Start SectLevel3 --> <h4><a name="How can I count the number of query results without actually returning them?">How can I count the number of query results without actually returning them?</a></h4> <pre> *************** *** 202,232 **** </pre> <!--End Section 3--> - <h4><a name="How do I specify the length of a column for the SchemExport tool? A unique column? A not-null column?">How do I specify the length of a column for the SchemExport tool? A unique column? A not-null column?</a></h4> - <p class="Body"> - Column lengths and constraints may be specified in the mapping document. If you browse - </p> - <p class="Body"> - <a href="http://hibernate.sourceforge.net/hibernate-mapping.dtd">http://hibernate.sourceforge.net/hibernate-mapping.dtd</a> - </p> - <p class="Body"> - you will find it quite well documented. - </p> - <!--End Section 3--> - <h4><a name="What column should I map the index tag of an array or List to?">What column should I map the index tag of an array or List to?</a></h4> - <p class="Body"> - You need a seperate table column holding the array or List index (the <tt>i</tt> in <tt>foo[i]</tt>)! If your relational model doesn't have an index column, use a <tt>Set</tt> instead. This seems to put people off who assume that <tt>List</tt> should just be a more convenient way of accessing an unordered collection. Hibernate collections strictly obey the actual semantics attached to the <tt>Set</tt>, <tt>List</tt>, <tt>Map</tt> interfaces. <tt>List</tt> elements don't just spontaneously rearrange themselves. - </p> - <p class="Body"> - On the other hand, people who planned to use the <tt>List</tt> to emulate "bag"-style semantics have a legitimate grievance here. Fortunately you can map a <tt>List</tt> or <tt>Collection</tt> with bag semantics. - </p> - <!--End Section 3--> - <h4><a name="What are bags for?">What are bags for?</a></h4> - <p class="Body"> - A bag is an unordered, unindexed collection which can contain the same element multiple times. The Java collections framework lacks a <tt>Bag</tt> interface (though you can emulate it with a <tt>List</tt>). Hibernate lets you map properties of type <tt>List</tt> or <tt>Collection</tt> with the <tt><bag></tt> element. Note that bag semantics are not really part of the <tt>Collection</tt> contract and they actually conflict with the semantics of <tt>List</tt>. - </p> - <p class="Body"> - Large Hibernate bags are inefficient and should be avoided. (Hibernate can't create, delete or update rows individually.) - </p> - <!--End Section 3--> <h4><a name="I have a one-to-one association between two classes. Ensuring that associated objects have matching identifiers is bugprone. Is there a better way?">I have a one-to-one association between two classes. Ensuring that associated objects have matching identifiers is bugprone. Is there a better way?</a></h4> <p class="Body"> --- 295,298 ---- *************** *** 287,347 **** </pre> <!--End Section 3--> ! <h4><a name="I removed an object from a collection mapped with cascade="all" but the object was not deleted !">I removed an object from a collection mapped with cascade="all" but the object was not deleted !</a></h4> ! <p class="Body"> ! <tt>cascade="all"</tt> cascades the <tt>delete()</tt> operation from parent to child. Hibernate <strong>never</strong> deletes an entity without an explicit call to <tt>delete()</tt>. If you aren't deleting the parent object, you will have to explicitly delete the child. ! </p> ! <p class="Body"> ! On the other hand, if you really want to avoid explicitly deleting collection elements, one solution is to model them as value types rather than entities. (Value types are always persisted or removed along with their parent entity.) So you would use a <tt><composite-element></tt> mapping for the element class instead of modelling it as a seperate entity. ! </p> ! <!--End Section 3--> ! <h4><a name="I'm confused about the semantics of saveOrUpdate()">I'm confused about the semantics of saveOrUpdate()</a></h4> ! <p class="Body"> ! Firstly, so long as you are not trying to use instances from one session in another new session, you should not need to use <tt>update()</tt> or <tt>saveOrUpdate()</tt>. Some whole applications will never use either of these methods. ! </p> ! <p class="Body"> ! Usually <tt>update()</tt> or <tt>saveOrUpdate()</tt> are used in the following scenario: ! </p> ! <ol> ! <li> the application loads an object in the first session</li> ! <li> the object is passed up to the UI tier</li> ! <li> some modifications are made to the object</li> ! <li> the object is passed back down</li> ! <li> the application persists these modifications by calling <tt>update()</tt> in a second session</li> ! </ol> ! <p class="Body"> ! <tt>saveOrUpdate()</tt> does the following: ! </p> ! <ol> ! <li> if the object is already persistent in this session, do nothing</li> ! <li> if the object has no identifier property, <tt>save()</tt> it</li> ! <li> if the object's identifier matches the criteria specified by <tt>unsaved-value</tt>, <tt>save()</tt> it</li> ! <li> if another object associated with the session has the same identifier, throw an exception </li> ! <li> overwrite the existing state associated with the given object's identifier</li> ! </ol> ! <!--End Section 3--> ! <h4><a name="I'm using a one-to-many association with a NOT NULL constraint on the key column and Hibernate causes constraint violations.">I'm using a one-to-many association with a NOT NULL constraint on the key column and Hibernate causes constraint violations.</a></h4> ! <p class="Body"> ! Use a bidirectional association (mapping the many-valued end with <tt>readonly="true"</tt>). ! </p> ! <!--End Section 3--> ! <h4><a name="Hibernate is violating a unique constraint!">Hibernate is violating a unique constraint!</a></h4> ! <p class="Body"> ! Hibernate isn't quite as clever with unique constraints as it is with foreign keys. Sometimes you might need to give a little hint. ! </p> <p class="Body"> ! A unique constraint violation could occur if two objects are both being updated, one is "releasing" a value and the other is "obtaining" the same value. A workaround is to <tt>flush()</tt> the session manually after updating the first object and before updating the second. </p> <p class="Body"> ! (This kind of problem occurs rarely in practice.) </p> <!--End Section 3--> ! <h4><a name="I'm supplying my own connections to Hibernate and I see exceptions like: "too many opened cursors"">I'm supplying my own connections to Hibernate and I see exceptions like: "too many opened cursors"</a></h4> ! <p class="Body"> ! You must disable <tt... [truncated message content] |