You can subscribe to this list here.
2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(22) |
Nov
(308) |
Dec
(131) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(369) |
Feb
(171) |
Mar
(236) |
Apr
(187) |
May
(218) |
Jun
(217) |
Jul
(127) |
Aug
(448) |
Sep
(270) |
Oct
(231) |
Nov
(422) |
Dec
(255) |
2004 |
Jan
(111) |
Feb
(73) |
Mar
(338) |
Apr
(351) |
May
(349) |
Jun
(495) |
Jul
(394) |
Aug
(1048) |
Sep
(499) |
Oct
(142) |
Nov
(269) |
Dec
(638) |
2005 |
Jan
(825) |
Feb
(1272) |
Mar
(593) |
Apr
(690) |
May
(950) |
Jun
(958) |
Jul
(767) |
Aug
(839) |
Sep
(525) |
Oct
(449) |
Nov
(585) |
Dec
(455) |
2006 |
Jan
(603) |
Feb
(656) |
Mar
(195) |
Apr
(114) |
May
(136) |
Jun
(100) |
Jul
(128) |
Aug
(68) |
Sep
(7) |
Oct
(1) |
Nov
(1) |
Dec
(8) |
2007 |
Jan
(4) |
Feb
(3) |
Mar
(8) |
Apr
(16) |
May
(5) |
Jun
(4) |
Jul
(6) |
Aug
(23) |
Sep
(15) |
Oct
(5) |
Nov
(7) |
Dec
(5) |
2008 |
Jan
(5) |
Feb
(1) |
Mar
(1) |
Apr
(5) |
May
(1) |
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
2009 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
2012 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
(1) |
Jul
(1) |
Aug
(1) |
Sep
|
Oct
(2) |
Nov
(3) |
Dec
(2) |
2013 |
Jan
(1) |
Feb
|
Mar
(2) |
Apr
(1) |
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2014 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
(2) |
Jun
(1) |
Jul
|
Aug
(1) |
Sep
(1) |
Oct
|
Nov
(1) |
Dec
|
2015 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
|
2016 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2017 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <one...@us...> - 2002-11-11 01:25:11
|
Update of /cvsroot/hibernate/Hibernate In directory usw-pr-cvs1:/tmp/cvs-serv27549 Modified Files: build.xml changelog.txt Log Message: changes / bugfixes to MapGenerator tool Index: build.xml =================================================================== RCS file: /cvsroot/hibernate/Hibernate/build.xml,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** build.xml 1 Nov 2002 00:21:26 -0000 1.29 --- build.xml 11 Nov 2002 01:25:06 -0000 1.30 *************** *** 17,21 **** <property name="Name" value="Hibernate"/> <property name="name" value="hibernate"/> ! <property name="version" value="1.1"/> <!-- set global properties for this build --> --- 17,21 ---- <property name="Name" value="Hibernate"/> <property name="name" value="hibernate"/> ! <property name="version" value="1.2"/> <!-- set global properties for this build --> Index: changelog.txt =================================================================== RCS file: /cvsroot/hibernate/Hibernate/changelog.txt,v retrieving revision 1.261 retrieving revision 1.262 diff -C2 -d -r1.261 -r1.262 *** changelog.txt 10 Nov 2002 03:46:21 -0000 1.261 --- changelog.txt 11 Nov 2002 01:25:06 -0000 1.262 *************** *** 19,22 **** --- 19,23 ---- * CodeGenerator now generates isFoo() style getters for boolean properties (patch by Aapo Laakkonen) * components may now have a nonpublic constructor (patch by Jon Lipsky) + * changes / bugfixes to MapGenerator tool Changes in version 1.1.8 (30.10.2002) |
From: <one...@us...> - 2002-11-11 01:25:11
|
Update of /cvsroot/hibernate/Hibernate/bin In directory usw-pr-cvs1:/tmp/cvs-serv27549/bin Modified Files: MapGenerator.bat Log Message: changes / bugfixes to MapGenerator tool Index: MapGenerator.bat =================================================================== RCS file: /cvsroot/hibernate/Hibernate/bin/MapGenerator.bat,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MapGenerator.bat 31 Oct 2002 17:38:49 -0000 1.1 --- MapGenerator.bat 11 Nov 2002 01:25:06 -0000 1.2 *************** *** 10,12 **** set CP=%JDBC_DRIVER%;%HIBERNATE_HOME%;%HIBERNATE_HOME%\hibernate.jar;%LIB%\commons-logging.jar;%LIB%\commons-collections.jar;%LIB%\commons-lang.jar;%LIB%\cglib.jar;%LIB%\bcel.jar;%LIB%\odmg.jar;%LIB%\jdom.jar;%LIB%\xml-apis.jar;%LIB%\xerces.jar;%LIB%\xalan.jar ! java -cp CP cirrus.hibernate.tools.MapGenerator %* --- 10,12 ---- set CP=%JDBC_DRIVER%;%HIBERNATE_HOME%;%HIBERNATE_HOME%\hibernate.jar;%LIB%\commons-logging.jar;%LIB%\commons-collections.jar;%LIB%\commons-lang.jar;%LIB%\cglib.jar;%LIB%\bcel.jar;%LIB%\odmg.jar;%LIB%\jdom.jar;%LIB%\xml-apis.jar;%LIB%\xerces.jar;%LIB%\xalan.jar ! java -cp %CP% cirrus.hibernate.tools.MapGenerator %* |
From: <one...@us...> - 2002-11-11 00:09:21
|
Update of /cvsroot/hibernate/Hibernate/cirrus/hibernate/eg In directory usw-pr-cvs1:/tmp/cvs-serv8802 Modified Files: Edge.hbm.xml Vertex.hbm.xml Log Message: eg package now uses 1.1 DTD Index: Edge.hbm.xml =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/eg/Edge.hbm.xml,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Edge.hbm.xml 26 Jul 2002 04:25:30 -0000 1.8 --- Edge.hbm.xml 11 Nov 2002 00:09:18 -0000 1.9 *************** *** 2,6 **** <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" ! "http://hibernate.sourceforge.net/hibernate-mapping.dtd"> <hibernate-mapping> --- 2,6 ---- <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" ! "http://hibernate.sourceforge.net/hibernate-mapping-1.1.dtd"> <hibernate-mapping> Index: Vertex.hbm.xml =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/eg/Vertex.hbm.xml,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Vertex.hbm.xml 20 Aug 2002 11:13:10 -0000 1.13 --- Vertex.hbm.xml 11 Nov 2002 00:09:18 -0000 1.14 *************** *** 2,6 **** <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" ! "http://hibernate.sourceforge.net/hibernate-mapping.dtd"> <hibernate-mapping> --- 2,6 ---- <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" ! "http://hibernate.sourceforge.net/hibernate-mapping-1.1.dtd"> <hibernate-mapping> *************** *** 19,28 **** <set role="incoming" lazy="true" readonly="true" cascade="all" order-by="name"> ! <key column="sink" type="long"/> <one-to-many class="cirrus.hibernate.eg.Edge"/> </set> <set role="outgoing" lazy="true" readonly="true" cascade="all" order-by="name desc"> ! <key column="source" type="long"/> <one-to-many class="cirrus.hibernate.eg.Edge"/> </set> --- 19,28 ---- <set role="incoming" lazy="true" readonly="true" cascade="all" order-by="name"> ! <key column="sink"/> <one-to-many class="cirrus.hibernate.eg.Edge"/> </set> <set role="outgoing" lazy="true" readonly="true" cascade="all" order-by="name desc"> ! <key column="source"/> <one-to-many class="cirrus.hibernate.eg.Edge"/> </set> |
From: <one...@us...> - 2002-11-10 15:19:52
|
Update of /cvsroot/hibernate/Hibernate/cirrus/hibernate/tools/codegen In directory usw-pr-cvs1:/tmp/cvs-serv12595 Modified Files: ClassMapping.java Log Message: Max Andersen's patch for one-to-one support in codegenerator Index: ClassMapping.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/tools/codegen/ClassMapping.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** ClassMapping.java 21 Oct 2002 03:45:04 -0000 1.12 --- ClassMapping.java 10 Nov 2002 15:19:48 -0000 1.13 *************** *** 13,16 **** --- 13,17 ---- import cirrus.hibernate.type.Type; + import org.apache.commons.lang.StringUtils; import org.jdom.Attribute; import org.jdom.Element; *************** *** 70,74 **** // ensure that the type is specified String type = property.getAttributeValue("type"); ! if ( type == null || type.trim().equals("") ) { System.out.println("property \"" + name + "\" in class " + getName() + " is missing a type attribute"); continue; --- 71,75 ---- // ensure that the type is specified String type = property.getAttributeValue("type"); ! if (StringUtils.isEmpty(type)) { System.out.println("property \"" + name + "\" in class " + getName() + " is missing a type attribute"); continue; *************** *** 99,102 **** --- 100,121 ---- } } + + List onetooneList = classElement.getChildren("one-to-one"); + for (Iterator onetoones = onetooneList.iterator(); onetoones.hasNext();) { + Element onetoone = (Element) onetoones.next(); + + String name = onetoone.getAttributeValue("name"); + + // ensure that the class is specified + String clazz = onetoone.getAttributeValue("class"); + if(StringUtils.isEmpty(clazz)) { + System.out.println("one-to-one \"" + name + "\" in class " + getName() + " is missing a class attribute"); + continue; + } + + fields.add(new Field(name, getFieldType(clazz), true)); + + } + // many to ones - TODO: consolidate with code above |
From: <one...@us...> - 2002-11-10 15:19:52
|
Update of /cvsroot/hibernate/Hibernate/cirrus/hibernate/tools/codegen/test In directory usw-pr-cvs1:/tmp/cvs-serv12595/test Modified Files: Test.hbm.xml Test2.hbm.xml Log Message: Max Andersen's patch for one-to-one support in codegenerator Index: Test.hbm.xml =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/tools/codegen/test/Test.hbm.xml,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Test.hbm.xml 14 Sep 2002 07:25:09 -0000 1.2 --- Test.hbm.xml 10 Nov 2002 15:19:49 -0000 1.3 *************** *** 58,60 **** --- 58,66 ---- </subclass> </class> + + <class name="codegen.test.Person"> + <id name="id" type="string"><generator class="assigned"/></id> + <one-to-one name="myUser" class="codegen.test.User"/> + </class> + </hibernate-mapping> Index: Test2.hbm.xml =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/tools/codegen/test/Test2.hbm.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Test2.hbm.xml 9 Oct 2002 03:52:11 -0000 1.1 --- Test2.hbm.xml 10 Nov 2002 15:19:49 -0000 1.2 *************** *** 41,43 **** --- 41,57 ---- </set> </class> + + <!-- dummy classes to make the test complete --> + <!-- also tests support for classes with no properties --> + <class name="ClassB"> + <id name="id" type="int"> + <generator class="uuid.hex"/> + </id> + </class> + + <class name="ClassA"> + <id name="id" type="int"> + <generator class="uuid.hex"/> + </id> + </class> </hibernate-mapping> |
From: <one...@us...> - 2002-11-10 03:46:25
|
Update of /cvsroot/hibernate/Hibernate In directory usw-pr-cvs1:/tmp/cvs-serv14120 Modified Files: changelog.txt Log Message: changelog Index: changelog.txt =================================================================== RCS file: /cvsroot/hibernate/Hibernate/changelog.txt,v retrieving revision 1.260 retrieving revision 1.261 diff -C2 -d -r1.260 -r1.261 *** changelog.txt 7 Nov 2002 16:14:00 -0000 1.260 --- changelog.txt 10 Nov 2002 03:46:21 -0000 1.261 *************** *** 10,14 **** * fixed a problem with outerjoin fetching of one-to-one associations defined on subclasses * fixed a minor problem with proxies of classes that override finalize() ! * finished work on normalized table mappings using <joined-subclass> declaration * deprecated hibernate-mapping.dtd in favor of hibernate-mapping-1.1.dtd * reworked unmapped class / interface / table-per-concrete-class query functionality, fixing several problems --- 10,14 ---- * fixed a problem with outerjoin fetching of one-to-one associations defined on subclasses * fixed a minor problem with proxies of classes that override finalize() ! * finished work on normalized table mappings using <joined-subclass> declaration (only for databases with ANSI OUTER JOIN and CASE) * deprecated hibernate-mapping.dtd in favor of hibernate-mapping-1.1.dtd * reworked unmapped class / interface / table-per-concrete-class query functionality, fixing several problems *************** *** 17,20 **** --- 17,22 ---- * fixed some problems with embedded composite identifiers * fixed a bug cascading deletes to one-to-one associations + * CodeGenerator now generates isFoo() style getters for boolean properties (patch by Aapo Laakkonen) + * components may now have a nonpublic constructor (patch by Jon Lipsky) Changes in version 1.1.8 (30.10.2002) |
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] |
From: <one...@us...> - 2002-11-09 01:49:26
|
Update of /cvsroot/hibernate/Hibernate/cirrus/hibernate/type In directory usw-pr-cvs1:/tmp/cvs-serv8934/hibernate/type Modified Files: ComponentType.java Log Message: cache the constructor Index: ComponentType.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/type/ComponentType.java,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** ComponentType.java 9 Nov 2002 01:38:06 -0000 1.45 --- ComponentType.java 9 Nov 2002 01:49:23 -0000 1.46 *************** *** 22,25 **** --- 22,26 ---- private final Class componentClass; + private final Constructor constructor; private final Type[] types; private final Method[] getters; *************** *** 78,81 **** --- 79,83 ---- this.cascade = cascade; this.joinedFetch = joinedFetch; + constructor = ReflectHelper.getDefaultConstructor(componentClass); } *************** *** 217,221 **** public Object instantiate(Object parent) throws HibernateException { try { - Constructor constructor = ReflectHelper.getDefaultConstructor(componentClass); Object inst = constructor.newInstance(null); if (parentSetter!=null) ReflectHelper.set(parentSetter, inst, parent, componentClass, parentProperty); --- 219,222 ---- |
From: <one...@us...> - 2002-11-09 01:38:10
|
Update of /cvsroot/hibernate/Hibernate/cirrus/hibernate/type In directory usw-pr-cvs1:/tmp/cvs-serv6168/hibernate/type Modified Files: ComponentType.java Log Message: committed Jon Lipsky's patch to allow components with private constructors Index: ComponentType.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/type/ComponentType.java,v retrieving revision 1.44 retrieving revision 1.45 diff -C2 -d -r1.44 -r1.45 *** ComponentType.java 27 Oct 2002 18:30:56 -0000 1.44 --- ComponentType.java 9 Nov 2002 01:38:06 -0000 1.45 *************** *** 1,275 **** ! //$Id$ ! package cirrus.hibernate.type; ! ! import java.io.Serializable; ! import java.lang.reflect.Method; ! import java.sql.PreparedStatement; ! import java.sql.ResultSet; ! import java.sql.SQLException; ! ! import cirrus.hibernate.HibernateException; ! import cirrus.hibernate.InstantiationException; ! import cirrus.hibernate.MappingException; ! import cirrus.hibernate.engine.Cascades; ! import cirrus.hibernate.engine.Mapping; ! import cirrus.hibernate.engine.SessionFactoryImplementor; ! import cirrus.hibernate.engine.SessionImplementor; ! import cirrus.hibernate.helpers.ArrayHelper; ! import cirrus.hibernate.helpers.ReflectHelper; ! ! public class ComponentType extends AbstractType implements AbstractComponentType { ! ! private final Class componentClass; ! private final Type[] types; ! private final Method[] getters; ! private final Method[] setters; ! private final String[] propertyNames; ! private final Cascades.CascadeStyle[] cascade; ! private final int propertySpan; ! private final int[] joinedFetch; ! private final String parentProperty; ! private final Method parentSetter; ! ! public int[] sqlTypes(Mapping pi) throws MappingException { ! //Not called at runtime so doesn't matter if its slow :) ! int[] sqlTypes = new int[ getColumnSpan(pi) ]; ! int n=0; ! for ( int i=0; i<propertySpan; i++ ) { ! int[] subtypes = types[i].sqlTypes(pi); ! for ( int j=0; j<subtypes.length; j++ ) { ! sqlTypes[n++] = subtypes[j]; ! } ! } ! return sqlTypes; ! } ! ! public int getColumnSpan(Mapping pi) throws MappingException { ! int span = 0; ! for ( int i=0; i<types.length; i++ ) { ! span += types[i].getColumnSpan(pi); ! } ! return span; ! } ! ! public ComponentType( ! Class componentClass, ! Type[] types, ! String[] properties, ! int[] joinedFetch, ! Cascades.CascadeStyle[] ! cascade, ! String parentProperty, ! boolean embedded ! ) throws MappingException { ! ! this.componentClass = componentClass; ! this.types = types; ! propertySpan = properties.length; ! getters = new Method[propertySpan]; ! setters = new Method[propertySpan]; ! for ( int i=0; i<properties.length; i++ ) { ! getters[i] = ReflectHelper.getGetterMethod( componentClass, properties[i] ); ! setters[i] = ReflectHelper.getSetterMethod( componentClass, properties[i] ); ! } ! this.parentSetter = (parentProperty==null) ? null : ReflectHelper.getSetterMethod(componentClass, parentProperty); ! this.parentProperty = parentProperty; ! this.propertyNames = properties; ! this.cascade = cascade; ! this.joinedFetch = joinedFetch; ! } ! ! public boolean isPersistentCollectionType() { ! return false; ! } ! public final boolean isComponentType() { ! return true; ! } ! public final boolean isEntityType() { ! return false; ! } ! ! public Class returnedClass() { ! return componentClass; ! } ! ! public boolean equals(Object x, Object y) throws HibernateException { ! if (x==y) return true; ! if (x==null || y==null) return false; ! for ( int i=0; i<getters.length; i++ ) { ! try { ! if ( !types[i].equals( getters[i].invoke(x, null), getters[i].invoke(y, null) ) ) return false; ! } ! catch (Exception e) { ! throw new HibernateException( "Could not compare component property values: " + componentClass.getName() ); ! } ! } ! return true; ! } ! ! public boolean isDirty(Object x, Object y, Object owner, SessionFactoryImplementor factory) throws HibernateException { ! if (x==y) return false; ! if (x==null || y==null) return true; ! for ( int i=0; i<getters.length; i++ ) { ! try { ! if ( types[i].isDirty( getters[i].invoke(x, null), getters[i].invoke(y, null), owner, factory ) ) return true; ! } ! catch (Exception e) { ! throw new HibernateException( "Could not compare component property values: " + componentClass.getName() ); ! } ! } ! return false; ! } ! ! public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) ! throws HibernateException, SQLException { ! ! int begin=0; ! boolean notNull=false; ! Object[] values = new Object[propertySpan]; ! for ( int i=0; i<propertySpan; i++ ) { ! int length = types[i].getColumnSpan( session.getFactory() ); ! String[] range = ArrayHelper.slice(names, begin, length); //cache this ! Object val = types[i].nullSafeGet(rs, range, session, owner); ! if (val!=null) notNull=true; ! values[i] = val; ! begin+=length; ! } ! ! if (notNull) { ! Object result = instantiate(owner); ! for ( int i=0; i<propertySpan; i++ ) { ! ReflectHelper.set( setters[i], result, values[i], componentClass, propertyNames[i] ); ! } ! return result; ! } ! else { ! return null; ! } ! } ! ! public void nullSafeSet(PreparedStatement st, Object value, int begin, SessionImplementor session) ! throws HibernateException, SQLException { ! ! Object[] subvalues = nullSafeGetValues(value); ! ! for ( int i=0; i<propertySpan; i++ ) { ! types[i].nullSafeSet(st, subvalues[i], begin, session); ! begin += types[i].getColumnSpan( session.getFactory() ); ! } ! } ! ! private Object[] nullSafeGetValues(Object value) throws HibernateException { ! if ( value==null ) { ! return new Object[propertySpan]; ! } ! else { ! return getPropertyValues(value); ! } ! } ! ! public Object nullSafeGet(ResultSet rs, String name, SessionImplementor session, Object owner) ! throws HibernateException, SQLException { ! ! return nullSafeGet(rs, new String[] {name}, session, owner); ! } ! ! public Object getPropertyValue(Object component, int i) throws HibernateException { ! return ReflectHelper.get( getters[i], component, componentClass, propertyNames[i] ); ! } ! ! public Object[] getPropertyValues(Object component) throws HibernateException { ! Object[] values = new Object[propertySpan]; ! for ( int i=0; i<propertySpan; i++ ) { ! values[i] = getPropertyValue(component, i); ! } ! return values; ! } ! ! public void setPropertyValues(Object component, Object[] values) throws HibernateException { ! for ( int i=0; i<propertySpan; i++ ) { ! ReflectHelper.set( setters[i], component, values[i], componentClass, propertyNames[i] ); ! } ! } ! public Type[] getSubtypes() { ! return types; ! } ! public String getName() { return componentClass.getName(); } ! public String toXML(Object value, SessionFactoryImplementor factory) { ! return (value==null) ? null : value.toString(); ! } ! public String[] getPropertyNames() { ! return propertyNames; ! } ! ! public Object deepCopy(Object component) throws HibernateException { ! if (component==null) return null; ! ! Object[] values = getPropertyValues(component); ! for ( int i=0; i<propertySpan; i++ ) { ! values[i] = types[i].deepCopy( values[i] ); ! } ! Object result = instantiate(null); //TODO: note that this doesn't copy reference to parent. Is that okay?? ! setPropertyValues(result, values); ! return result; ! } ! ! public Object instantiate(Object parent) throws HibernateException { ! try { ! Object inst = componentClass.newInstance(); ! if (parentSetter!=null) ReflectHelper.set(parentSetter, inst, parent, componentClass, parentProperty); ! return inst; ! } ! catch (Exception e) { ! throw new InstantiationException("Could not instantiate component ", componentClass, e); ! } ! } ! ! public Cascades.CascadeStyle cascade(int i) { ! return cascade[i]; ! } ! ! public boolean isMutable() { ! return true; ! } ! ! public Serializable disassemble(Object value, SessionImplementor session) ! throws HibernateException { ! ! if (value==null) { ! return null; ! } ! else { ! Object[] values = getPropertyValues(value); ! for ( int i=0; i<types.length; i++ ) { ! values[i] = types[i].disassemble(values[i], session); ! } ! return values; ! } ! } ! ! public Object assemble(Serializable object, SessionImplementor session, Object owner) throws HibernateException, SQLException { ! if ( object==null ) { ! return null; ! } ! else { ! Object[] values = (Object[]) object; ! Object[] assembled = new Object[values.length]; ! for ( int i=0; i<types.length; i++ ) { ! assembled[i] = types[i].assemble( (Serializable) values[i], session, owner ); ! } ! Object result = instantiate(owner); ! setPropertyValues(result, assembled); ! return result; ! } ! } ! ! public boolean hasNiceEquals() { ! return false; ! } ! ! public int enableJoinedFetch(int i) { ! return joinedFetch[i]; ! } ! ! } ! --- 1,277 ---- ! //$Id$ ! package cirrus.hibernate.type; ! ! import java.io.Serializable; ! import java.lang.reflect.Constructor; ! import java.lang.reflect.Method; ! import java.sql.PreparedStatement; ! import java.sql.ResultSet; ! import java.sql.SQLException; ! ! import cirrus.hibernate.HibernateException; ! import cirrus.hibernate.InstantiationException; ! import cirrus.hibernate.MappingException; ! import cirrus.hibernate.engine.Cascades; ! import cirrus.hibernate.engine.Mapping; ! import cirrus.hibernate.engine.SessionFactoryImplementor; ! import cirrus.hibernate.engine.SessionImplementor; ! import cirrus.hibernate.helpers.ArrayHelper; ! import cirrus.hibernate.helpers.ReflectHelper; ! ! public class ComponentType extends AbstractType implements AbstractComponentType { ! ! private final Class componentClass; ! private final Type[] types; ! private final Method[] getters; ! private final Method[] setters; ! private final String[] propertyNames; ! private final Cascades.CascadeStyle[] cascade; ! private final int propertySpan; ! private final int[] joinedFetch; ! private final String parentProperty; ! private final Method parentSetter; ! ! public int[] sqlTypes(Mapping pi) throws MappingException { ! //Not called at runtime so doesn't matter if its slow :) ! int[] sqlTypes = new int[ getColumnSpan(pi) ]; ! int n=0; ! for ( int i=0; i<propertySpan; i++ ) { ! int[] subtypes = types[i].sqlTypes(pi); ! for ( int j=0; j<subtypes.length; j++ ) { ! sqlTypes[n++] = subtypes[j]; ! } ! } ! return sqlTypes; ! } ! ! public int getColumnSpan(Mapping pi) throws MappingException { ! int span = 0; ! for ( int i=0; i<types.length; i++ ) { ! span += types[i].getColumnSpan(pi); ! } ! return span; ! } ! ! public ComponentType( ! Class componentClass, ! Type[] types, ! String[] properties, ! int[] joinedFetch, ! Cascades.CascadeStyle[] ! cascade, ! String parentProperty, ! boolean embedded ! ) throws MappingException { ! ! this.componentClass = componentClass; ! this.types = types; ! propertySpan = properties.length; ! getters = new Method[propertySpan]; ! setters = new Method[propertySpan]; ! for ( int i=0; i<properties.length; i++ ) { ! getters[i] = ReflectHelper.getGetterMethod( componentClass, properties[i] ); ! setters[i] = ReflectHelper.getSetterMethod( componentClass, properties[i] ); ! } ! this.parentSetter = (parentProperty==null) ? null : ReflectHelper.getSetterMethod(componentClass, parentProperty); ! this.parentProperty = parentProperty; ! this.propertyNames = properties; ! this.cascade = cascade; ! this.joinedFetch = joinedFetch; ! } ! ! public boolean isPersistentCollectionType() { ! return false; ! } ! public final boolean isComponentType() { ! return true; ! } ! public final boolean isEntityType() { ! return false; ! } ! ! public Class returnedClass() { ! return componentClass; ! } ! ! public boolean equals(Object x, Object y) throws HibernateException { ! if (x==y) return true; ! if (x==null || y==null) return false; ! for ( int i=0; i<getters.length; i++ ) { ! try { ! if ( !types[i].equals( getters[i].invoke(x, null), getters[i].invoke(y, null) ) ) return false; ! } ! catch (Exception e) { ! throw new HibernateException( "Could not compare component property values: " + componentClass.getName() ); ! } ! } ! return true; ! } ! ! public boolean isDirty(Object x, Object y, Object owner, SessionFactoryImplementor factory) throws HibernateException { ! if (x==y) return false; ! if (x==null || y==null) return true; ! for ( int i=0; i<getters.length; i++ ) { ! try { ! if ( types[i].isDirty( getters[i].invoke(x, null), getters[i].invoke(y, null), owner, factory ) ) return true; ! } ! catch (Exception e) { ! throw new HibernateException( "Could not compare component property values: " + componentClass.getName() ); ! } ! } ! return false; ! } ! ! public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) ! throws HibernateException, SQLException { ! ! int begin=0; ! boolean notNull=false; ! Object[] values = new Object[propertySpan]; ! for ( int i=0; i<propertySpan; i++ ) { ! int length = types[i].getColumnSpan( session.getFactory() ); ! String[] range = ArrayHelper.slice(names, begin, length); //cache this ! Object val = types[i].nullSafeGet(rs, range, session, owner); ! if (val!=null) notNull=true; ! values[i] = val; ! begin+=length; ! } ! ! if (notNull) { ! Object result = instantiate(owner); ! for ( int i=0; i<propertySpan; i++ ) { ! ReflectHelper.set( setters[i], result, values[i], componentClass, propertyNames[i] ); ! } ! return result; ! } ! else { ! return null; ! } ! } ! ! public void nullSafeSet(PreparedStatement st, Object value, int begin, SessionImplementor session) ! throws HibernateException, SQLException { ! ! Object[] subvalues = nullSafeGetValues(value); ! ! for ( int i=0; i<propertySpan; i++ ) { ! types[i].nullSafeSet(st, subvalues[i], begin, session); ! begin += types[i].getColumnSpan( session.getFactory() ); ! } ! } ! ! private Object[] nullSafeGetValues(Object value) throws HibernateException { ! if ( value==null ) { ! return new Object[propertySpan]; ! } ! else { ! return getPropertyValues(value); ! } ! } ! ! public Object nullSafeGet(ResultSet rs, String name, SessionImplementor session, Object owner) ! throws HibernateException, SQLException { ! ! return nullSafeGet(rs, new String[] {name}, session, owner); ! } ! ! public Object getPropertyValue(Object component, int i) throws HibernateException { ! return ReflectHelper.get( getters[i], component, componentClass, propertyNames[i] ); ! } ! ! public Object[] getPropertyValues(Object component) throws HibernateException { ! Object[] values = new Object[propertySpan]; ! for ( int i=0; i<propertySpan; i++ ) { ! values[i] = getPropertyValue(component, i); ! } ! return values; ! } ! ! public void setPropertyValues(Object component, Object[] values) throws HibernateException { ! for ( int i=0; i<propertySpan; i++ ) { ! ReflectHelper.set( setters[i], component, values[i], componentClass, propertyNames[i] ); ! } ! } ! public Type[] getSubtypes() { ! return types; ! } ! public String getName() { return componentClass.getName(); } ! public String toXML(Object value, SessionFactoryImplementor factory) { ! return (value==null) ? null : value.toString(); ! } ! public String[] getPropertyNames() { ! return propertyNames; ! } ! ! public Object deepCopy(Object component) throws HibernateException { ! if (component==null) return null; ! ! Object[] values = getPropertyValues(component); ! for ( int i=0; i<propertySpan; i++ ) { ! values[i] = types[i].deepCopy( values[i] ); ! } ! Object result = instantiate(null); //TODO: note that this doesn't copy reference to parent. Is that okay?? ! setPropertyValues(result, values); ! return result; ! } ! ! public Object instantiate(Object parent) throws HibernateException { ! try { ! Constructor constructor = ReflectHelper.getDefaultConstructor(componentClass); ! Object inst = constructor.newInstance(null); ! if (parentSetter!=null) ReflectHelper.set(parentSetter, inst, parent, componentClass, parentProperty); ! return inst; ! } ! catch (Exception e) { ! throw new InstantiationException("Could not instantiate component ", componentClass, e); ! } ! } ! ! public Cascades.CascadeStyle cascade(int i) { ! return cascade[i]; ! } ! ! public boolean isMutable() { ! return true; ! } ! ! public Serializable disassemble(Object value, SessionImplementor session) ! throws HibernateException { ! ! if (value==null) { ! return null; ! } ! else { ! Object[] values = getPropertyValues(value); ! for ( int i=0; i<types.length; i++ ) { ! values[i] = types[i].disassemble(values[i], session); ! } ! return values; ! } ! } ! ! public Object assemble(Serializable object, SessionImplementor session, Object owner) throws HibernateException, SQLException { ! if ( object==null ) { ! return null; ! } ! else { ! Object[] values = (Object[]) object; ! Object[] assembled = new Object[values.length]; ! for ( int i=0; i<types.length; i++ ) { ! assembled[i] = types[i].assemble( (Serializable) values[i], session, owner ); ! } ! Object result = instantiate(owner); ! setPropertyValues(result, assembled); ! return result; ! } ! } ! ! public boolean hasNiceEquals() { ! return false; ! } ! ! public int enableJoinedFetch(int i) { ! return joinedFetch[i]; ! } ! ! } ! |
From: <one...@us...> - 2002-11-09 01:38:10
|
Update of /cvsroot/hibernate/Hibernate/cirrus/hibernate/persister In directory usw-pr-cvs1:/tmp/cvs-serv6168/hibernate/persister Modified Files: AbstractEntityPersister.java Log Message: committed Jon Lipsky's patch to allow components with private constructors Index: AbstractEntityPersister.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/persister/AbstractEntityPersister.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** AbstractEntityPersister.java 6 Nov 2002 00:58:02 -0000 1.12 --- AbstractEntityPersister.java 9 Nov 2002 01:38:06 -0000 1.13 *************** *** 1,591 **** ! //$Id$ ! package cirrus.hibernate.persister; ! ! import java.io.Serializable; ! import java.lang.reflect.Constructor; ! import java.lang.reflect.Method; ! import java.lang.reflect.Modifier; ! import java.util.HashSet; ! import java.util.Iterator; ! [...1140 lines suppressed...] ! char quote = name.charAt(0); ! boolean nameEscaped = Dialect.QUOTE.indexOf(quote) > -1; ! ! if (nameEscaped) name = name.substring(1, name.length()-1); ! ! StringBuffer aliasBuilder = new StringBuffer(name.length()); ! ! if (nameEscaped) aliasBuilder.append(quote); ! aliasBuilder.append(name); ! aliasBuilder.append(suffix); ! if (nameEscaped) aliasBuilder.append(quote); ! ! return aliasBuilder.toString(); ! } ! ! public Class getMappedSuperclass() { ! return superclass; ! } ! ! } |
From: <one...@us...> - 2002-11-09 01:38:10
|
Update of /cvsroot/hibernate/Hibernate/cirrus/hibernate/helpers In directory usw-pr-cvs1:/tmp/cvs-serv6168/hibernate/helpers Modified Files: ReflectHelper.java Log Message: committed Jon Lipsky's patch to allow components with private constructors Index: ReflectHelper.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/helpers/ReflectHelper.java,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** ReflectHelper.java 28 Oct 2002 19:27:47 -0000 1.32 --- ReflectHelper.java 9 Nov 2002 01:38:05 -0000 1.33 *************** *** 1,227 **** ! //$Id$ ! package cirrus.hibernate.helpers; ! ! import java.beans.*; ! import java.lang.reflect.InvocationTargetException; ! import java.lang.reflect.Member; ! import java.lang.reflect.Method; ! import java.lang.reflect.Modifier; ! ! import cirrus.hibernate.*; ! import cirrus.hibernate.MappingException; ! import cirrus.hibernate.type.*; ! import cirrus.hibernate.type.Type; ! ! ! public final class ReflectHelper { ! ! private static final Class[] OBJECT = new Class[] { Object.class }; ! private static final Method OBJECT_EQUALS; ! static { ! Method eq; ! try { ! eq = Object.class.getMethod("equals", OBJECT); ! } ! catch (Exception e) { ! throw new AssertionFailure("Could not find Object.equals()", e); ! } ! OBJECT_EQUALS = eq; ! } ! ! public static boolean overridesEquals(Class clazz) { ! Method equals; ! try { ! equals = clazz.getMethod("equals", OBJECT); ! } ! catch (NoSuchMethodException nsme) { ! return false; //its an interface so we can't really tell anything... ! } ! return !OBJECT_EQUALS.equals(equals); ! } ! ! ! public static Method getMethod(Class theClass, String methodName) throws MappingException { ! ! if (theClass==Object.class || theClass==null) throw new MappingException( "Could not find a setter" ); // will be swallowed ! ! Method result; ! try { ! result = theClass.getDeclaredMethod(methodName, null); ! } ! catch (Exception e) { ! try { ! return getMethod( theClass.getSuperclass(), methodName ); ! } ! catch (MappingException me) { ! throw new MappingException( "Could not find method " + methodName + " in class " + theClass.getName() ); ! } ! } ! ! if ( !ReflectHelper.isPublic(theClass, result) ) result.setAccessible(true); ! return result; ! ! } ! ! public static Method getSetterMethod(Class theClass, String propertyName) throws MappingException { ! ! if (theClass==Object.class || theClass==null) throw new MappingException( "Could not find a setter" ); // will be swallowed ! ! Method result = setter(theClass, propertyName); ! ! if(result==null) { ! try { ! return getSetterMethod( theClass.getSuperclass(), propertyName ); ! } ! catch (MappingException me) { ! throw new MappingException( "Could not find a setter for " + propertyName + " in class " + theClass.getName() ); ! } ! } ! else { ! if ( !ReflectHelper.isPublic(theClass, result) ) result.setAccessible(true); ! return result; ! } ! ! } ! ! private static Method setter(Class theClass, String propertyName) { ! ! Method[] methods = theClass.getDeclaredMethods(); ! for (int i=0; i<methods.length; i++) { ! if( ! ( methods[i].getName().length() > 3 ) && ! ( methods[i].getName().startsWith("set") ) ! ) { ! String testStdMethod = Introspector.decapitalize( methods[i].getName().substring(3) ); ! String testOldMethod = methods[i].getName().substring(3); ! if ( ! ( testStdMethod.equals(propertyName) || testOldMethod.equals(propertyName) ) && ! ( methods[i].getParameterTypes().length==1 ) ! ) return methods[i]; ! } ! } ! return null; ! } ! ! public static Method getGetterMethod(Class theClass, String propertyName) throws MappingException { ! ! if (theClass==Object.class || theClass==null) throw new MappingException( "Could not find a getter" ); // will be swallowed ! ! Method result = getter(theClass, propertyName); ! ! if(result==null) { ! try { ! return getGetterMethod( theClass.getSuperclass(), propertyName ); ! } ! catch (MappingException me) { ! throw new MappingException( "Could not find a getter for " + propertyName + " in class " + theClass.getName() ); ! } ! } ! else { ! if ( !ReflectHelper.isPublic(theClass, result) ) result.setAccessible(true); ! return result; ! } ! } ! ! private static Method getter(Class theClass, String propertyName) { ! ! Method[] methods = theClass.getDeclaredMethods(); ! for (int i=0; i<methods.length; i++) { ! // only carry on if the method has no parameters ! if(methods[i].getParameterTypes().length==0) { ! ! // try "get" ! if( (methods[i].getName().length() > 3) && methods[i].getName().startsWith("get") ) { ! ! String testStdMethod = Introspector.decapitalize( methods[i].getName().substring(3) ); ! String testOldMethod = methods[i].getName().substring(3); ! if( ! ( testStdMethod.equals(propertyName) || testOldMethod.equals(propertyName) ) && ! methods[i].getParameterTypes().length==0 ! ) return methods[i]; ! ! } ! ! // if not "get" then try "is" ! if( (methods[i].getName().length() > 2) && methods[i].getName().startsWith("is") ) { ! ! String testStdMethod = Introspector.decapitalize( methods[i].getName().substring(2) ); ! String testOldMethod = methods[i].getName().substring(2); ! if( ! ( testStdMethod.equals(propertyName) || testOldMethod.equals(propertyName) ) && ! methods[i].getParameterTypes().length==0 ! ) return methods[i]; ! } ! } ! } ! return null; ! } ! ! public static Type reflectedPropertyType(Class theClass, String name) throws MappingException { ! return TypeFactory.hueristicType( getGetterMethod(theClass, name).getReturnType().getName() ); ! } ! ! public static Class classForName(String name) throws ClassNotFoundException { ! try { ! return Thread.currentThread().getContextClassLoader().loadClass(name); ! } ! catch (Exception e) { ! return Class.forName(name); ! } ! } ! ! public static void set(Method method, Object target, Object value, Class clazz, String propertyName) throws HibernateException { ! try { ! method.invoke( target, new Object[] { value } ); ! } ! catch (NullPointerException npe) { ! throw new PropertyAccessException(npe, "NullPointerException occurred inside", true, clazz, propertyName); ! } ! catch (InvocationTargetException ite) { ! throw new PropertyAccessException(ite, "Exception occurred inside", true, clazz, propertyName); ! } ! catch (IllegalAccessException iae) { ! throw new PropertyAccessException(iae, "IllegalAccessException occurred while calling", true, clazz, propertyName); ! //cannot occur ! } ! catch (IllegalArgumentException iae) { ! throw new PropertyAccessException(iae, "IllegalArgumentException occurred while calling", true, clazz, propertyName); ! } ! } ! ! public static Object get(Method method, Object target, Class clazz, String propertyName) throws HibernateException { ! try { ! return method.invoke(target, null); ! } ! catch (InvocationTargetException ite) { ! throw new PropertyAccessException(ite, "Exception occurred inside", false, clazz, propertyName); ! } ! catch (IllegalAccessException iae) { ! throw new PropertyAccessException(iae, "IllegalAccessException occurred while calling", false, clazz, propertyName); ! //cannot occur ! } ! catch (IllegalArgumentException iae) { ! throw new PropertyAccessException(iae, "IllegalArgumentException occurred calling", false, clazz, propertyName); ! } ! } ! ! public static boolean isPublic(Class clazz, Member member) { ! return Modifier.isPublic( member.getModifiers() ) && Modifier.isPublic( clazz.getModifiers() ); ! } ! ! public static Object getConstantValue(String name) { ! Class clazz; ! try { ! clazz = classForName( StringHelper.qualifier(name) ); ! } ! catch(ClassNotFoundException cnfe) { ! return null; ! } ! try { ! return clazz.getField( StringHelper.unqualify(name) ).get(null); ! } ! catch (Exception e) { ! return null; ! } ! } ! ! } --- 1,254 ---- ! //$Id$ ! package cirrus.hibernate.helpers; ! ! import java.beans.*; ! import java.lang.reflect.Constructor; ! import java.lang.reflect.InvocationTargetException; ! import java.lang.reflect.Member; ! import java.lang.reflect.Method; ! import java.lang.reflect.Modifier; ! ! import cirrus.hibernate.*; ! import cirrus.hibernate.MappingException; ! import cirrus.hibernate.type.*; ! import cirrus.hibernate.type.Type; ! ! ! public final class ReflectHelper { ! ! private static final Class[] NO_CLASSES = new Class[0]; ! private static final Class[] OBJECT = new Class[] { Object.class }; ! private static final Method OBJECT_EQUALS; ! ! static { ! Method eq; ! try { ! eq = Object.class.getMethod("equals", OBJECT); ! } ! catch (Exception e) { ! throw new AssertionFailure("Could not find Object.equals()", e); ! } ! OBJECT_EQUALS = eq; ! } ! ! public static boolean overridesEquals(Class clazz) { ! Method equals; ! try { ! equals = clazz.getMethod("equals", OBJECT); ! } ! catch (NoSuchMethodException nsme) { ! return false; //its an interface so we can't really tell anything... ! } ! return !OBJECT_EQUALS.equals(equals); ! } ! ! ! public static Method getMethod(Class theClass, String methodName) throws MappingException { ! ! if (theClass==Object.class || theClass==null) throw new MappingException( "Could not find a setter" ); // will be swallowed ! ! Method result; ! try { ! result = theClass.getDeclaredMethod(methodName, null); ! } ! catch (Exception e) { ! try { ! return getMethod( theClass.getSuperclass(), methodName ); ! } ! catch (MappingException me) { ! throw new MappingException( "Could not find method " + methodName + " in class " + theClass.getName() ); ! } ! } ! ! if ( !ReflectHelper.isPublic(theClass, result) ) result.setAccessible(true); ! return result; ! ! } ! ! public static Method getSetterMethod(Class theClass, String propertyName) throws MappingException { ! ! if (theClass==Object.class || theClass==null) throw new MappingException( "Could not find a setter" ); // will be swallowed ! ! Method result = setter(theClass, propertyName); ! ! if(result==null) { ! try { ! return getSetterMethod( theClass.getSuperclass(), propertyName ); ! } ! catch (MappingException me) { ! throw new MappingException( "Could not find a setter for " + propertyName + " in class " + theClass.getName() ); ! } ! } ! else { ! if ( !ReflectHelper.isPublic(theClass, result) ) result.setAccessible(true); ! return result; ! } ! ! } ! ! private static Method setter(Class theClass, String propertyName) { ! ! Method[] methods = theClass.getDeclaredMethods(); ! for (int i=0; i<methods.length; i++) { ! if( ! ( methods[i].getName().length() > 3 ) && ! ( methods[i].getName().startsWith("set") ) ! ) { ! String testStdMethod = Introspector.decapitalize( methods[i].getName().substring(3) ); ! String testOldMethod = methods[i].getName().substring(3); ! if ( ! ( testStdMethod.equals(propertyName) || testOldMethod.equals(propertyName) ) && ! ( methods[i].getParameterTypes().length==1 ) ! ) return methods[i]; ! } ! } ! return null; ! } ! ! public static Method getGetterMethod(Class theClass, String propertyName) throws MappingException { ! ! if (theClass==Object.class || theClass==null) throw new MappingException( "Could not find a getter" ); // will be swallowed ! ! Method result = getter(theClass, propertyName); ! ! if(result==null) { ! try { ! return getGetterMethod( theClass.getSuperclass(), propertyName ); ! } ! catch (MappingException me) { ! throw new MappingException( "Could not find a getter for " + propertyName + " in class " + theClass.getName() ); ! } ! } ! else { ! if ( !ReflectHelper.isPublic(theClass, result) ) result.setAccessible(true); ! return result; ! } ! } ! ! private static Method getter(Class theClass, String propertyName) { ! ! Method[] methods = theClass.getDeclaredMethods(); ! for (int i=0; i<methods.length; i++) { ! // only carry on if the method has no parameters ! if(methods[i].getParameterTypes().length==0) { ! ! // try "get" ! if( (methods[i].getName().length() > 3) && methods[i].getName().startsWith("get") ) { ! ! String testStdMethod = Introspector.decapitalize( methods[i].getName().substring(3) ); ! String testOldMethod = methods[i].getName().substring(3); ! if( ! ( testStdMethod.equals(propertyName) || testOldMethod.equals(propertyName) ) && ! methods[i].getParameterTypes().length==0 ! ) return methods[i]; ! ! } ! ! // if not "get" then try "is" ! if( (methods[i].getName().length() > 2) && methods[i].getName().startsWith("is") ) { ! ! String testStdMethod = Introspector.decapitalize( methods[i].getName().substring(2) ); ! String testOldMethod = methods[i].getName().substring(2); ! if( ! ( testStdMethod.equals(propertyName) || testOldMethod.equals(propertyName) ) && ! methods[i].getParameterTypes().length==0 ! ) return methods[i]; ! } ! } ! } ! return null; ! } ! ! public static Type reflectedPropertyType(Class theClass, String name) throws MappingException { ! return TypeFactory.hueristicType( getGetterMethod(theClass, name).getReturnType().getName() ); ! } ! ! public static Class classForName(String name) throws ClassNotFoundException { ! try { ! return Thread.currentThread().getContextClassLoader().loadClass(name); ! } ! catch (Exception e) { ! return Class.forName(name); ! } ! } ! ! public static void set(Method method, Object target, Object value, Class clazz, String propertyName) throws HibernateException { ! try { ! method.invoke( target, new Object[] { value } ); ! } ! catch (NullPointerException npe) { ! throw new PropertyAccessException(npe, "NullPointerException occurred inside", true, clazz, propertyName); ! } ! catch (InvocationTargetException ite) { ! throw new PropertyAccessException(ite, "Exception occurred inside", true, clazz, propertyName); ! } ! catch (IllegalAccessException iae) { ! throw new PropertyAccessException(iae, "IllegalAccessException occurred while calling", true, clazz, propertyName); ! //cannot occur ! } ! catch (IllegalArgumentException iae) { ! throw new PropertyAccessException(iae, "IllegalArgumentException occurred while calling", true, clazz, propertyName); ! } ! } ! ! public static Object get(Method method, Object target, Class clazz, String propertyName) throws HibernateException { ! try { ! return method.invoke(target, null); ! } ! catch (InvocationTargetException ite) { ! throw new PropertyAccessException(ite, "Exception occurred inside", false, clazz, propertyName); ! } ! catch (IllegalAccessException iae) { ! throw new PropertyAccessException(iae, "IllegalAccessException occurred while calling", false, clazz, propertyName); ! //cannot occur ! } ! catch (IllegalArgumentException iae) { ! throw new PropertyAccessException(iae, "IllegalArgumentException occurred calling", false, clazz, propertyName); ! } ! } ! ! public static boolean isPublic(Class clazz, Member member) { ! return Modifier.isPublic( member.getModifiers() ) && Modifier.isPublic( clazz.getModifiers() ); ! } ! ! public static Object getConstantValue(String name) { ! Class clazz; ! try { ! clazz = classForName( StringHelper.qualifier(name) ); ! } ! catch(ClassNotFoundException cnfe) { ! return null; ! } ! try { ! return clazz.getField( StringHelper.unqualify(name) ).get(null); ! } ! catch (Exception e) { ! return null; ! } ! } ! ! public static Constructor getDefaultConstructor(Class clazz) throws MappingException { ! ! if (isAbstractClass(clazz)) return null; ! ! try { ! Constructor constructor = clazz.getDeclaredConstructor(NO_CLASSES); ! if (!isPublic(clazz, constructor)) { ! constructor.setAccessible(true); ! } ! return constructor; ! } catch (NoSuchMethodException nme) { ! throw new MappingException( ! "Object class " + clazz.getName() + ! " must declare a default (no-argument) constructor" ! ); ! } ! ! } ! ! public static boolean isAbstractClass(Class clazz) { ! int modifier = clazz.getModifiers(); ! return (Modifier.isAbstract(modifier) || Modifier.isInterface(modifier)); ! } ! ! } |
From: <one...@us...> - 2002-11-08 23:49:50
|
Update of /cvsroot/hibernate/Hibernate/cirrus/hibernate/tools/codegen In directory usw-pr-cvs1:/tmp/cvs-serv7273/hibernate/tools/codegen Modified Files: BasicRenderer.java Log Message: integrated Aapo Laakkonen's patch to allow isFoo-style getters for boolean properties enabled order-by attribute for bags in JDK<1.4 Index: BasicRenderer.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/tools/codegen/BasicRenderer.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** BasicRenderer.java 2 Nov 2002 15:48:54 -0000 1.12 --- BasicRenderer.java 8 Nov 2002 23:49:47 -0000 1.13 *************** *** 2,11 **** package cirrus.hibernate.tools.codegen; - import java.io.PrintWriter; import java.util.Iterator; import java.util.Map; - public class BasicRenderer implements Renderer { --- 2,9 ---- *************** *** 14,18 **** * that it will return the Proxy for the class name if the class was * defined with a proxy attribute. ! * @param name class name that we use to serach in class2classmap * @param class2classmap a map from classname to classmappings * @return String return either name or the proxy name of the classmap --- 12,16 ---- * that it will return the Proxy for the class name if the class was * defined with a proxy attribute. ! * @param field class name that we use to serach in class2classmap * @param class2classmap a map from classname to classmappings * @return String return either name or the proxy name of the classmap *************** *** 142,147 **** field = (Field) fields.next(); // getter ! writer.println(" public " + getTrueTypeName(field, class2classmap) + " get" + field.getAsSuffix() + "() {"); writer.println(" return this." + field.getName() + ";"); writer.println(" }"); --- 140,147 ---- field = (Field) fields.next(); + String getterType = (field.getType().toLowerCase().equals("boolean")) ? " is" : " get"; + // getter ! writer.println(" public " + getTrueTypeName(field, class2classmap) + getterType + field.getAsSuffix() + "() {"); writer.println(" return this." + field.getName() + ";"); writer.println(" }"); |
From: <one...@us...> - 2002-11-08 23:49:50
|
Update of /cvsroot/hibernate/Hibernate/cirrus/hibernate/map In directory usw-pr-cvs1:/tmp/cvs-serv7273/hibernate/map Modified Files: Collection.java Log Message: integrated Aapo Laakkonen's patch to allow isFoo-style getters for boolean properties enabled order-by attribute for bags in JDK<1.4 Index: Collection.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/map/Collection.java,v retrieving revision 1.46 retrieving revision 1.47 diff -C2 -d -r1.46 -r1.47 *** Collection.java 5 Nov 2002 13:40:53 -0000 1.46 --- Collection.java 8 Nov 2002 23:49:47 -0000 1.47 *************** *** 79,83 **** Node orderNode = atts.getNamedItem("order-by"); if ( orderNode!=null) { ! if ( Environment.jvmSupportsLinkedHashCollections() ) { orderBy = orderNode.getNodeValue(); } --- 79,83 ---- Node orderNode = atts.getNamedItem("order-by"); if ( orderNode!=null) { ! if ( Environment.jvmSupportsLinkedHashCollections() || ( this instanceof Bag ) ) { orderBy = orderNode.getNodeValue(); } |
From: <one...@us...> - 2002-11-07 16:24:43
|
Update of /cvsroot/hibernate/Hibernate/doc In directory usw-pr-cvs1:/tmp/cvs-serv26764 Modified Files: faq.aft faq.aft-TOC faq.html Log Message: new faqs Index: faq.aft =================================================================== RCS file: /cvsroot/hibernate/Hibernate/doc/faq.aft,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** faq.aft 30 Oct 2002 15:28:04 -0000 1.26 --- faq.aft 7 Nov 2002 16:24:07 -0000 1.27 *************** *** 55,58 **** --- 55,96 ---- It doesn't. + *** I'm using a composite identifier and Hibernate causes a stack overfow! + + You _must_ override |equals()| and |hashCode()| correctly on your composite identifier class. This is quite critical. + + *** I'm seeing some strange behaviour with an embedded composite identifier or <key-many-to-one> when using proxies. + + It is actually surprisingly hard to get your implementation of |equals()| right when proxies are enabled. You must be prepared for the possibility that that a class instance is really a proxy for that class, so you can't access instance variables directly (use the accessors). + + And if you are using |<key-many-to-one>| you should compare entity equality by comparing identifiers instead of using |==|. + + *** 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. + + This kind of mapping is unsupported: + + <class name="BalanceSheet"> + .... + <set role="purchases"> + <key ....> + <one-to-many class="Purchase" column="bsid"/> + </set> + <set role="sales"> + <key ....> + <one-to-many class="Sale" column="bsid"/> + </set> + </class> + + <class name="Transaction"> + .... + <subclass name="Purchase".../> + <subclass name="Sale".../> + </class> + + You must either + + 1. map each association to a different column of the |Transaction| table + 2. map a single association and use a collection filter to retrieve instances of a particular subclass + 3. use a table-per-concrete-class mapping strategy for the |Transaction| hierarchy + *** How can I count the number of query results without actually returning them? *************** *** 85,92 **** you will find it quite well documented. - - *** How can I use quoted SQL identifiers? - - You can't. Sorry. We will fix this at some stage.... *** What column should I map the index tag of an array or List to? --- 123,126 ---- Index: faq.aft-TOC =================================================================== RCS file: /cvsroot/hibernate/Hibernate/doc/faq.aft-TOC,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** faq.aft-TOC 30 Oct 2002 15:28:05 -0000 1.17 --- faq.aft-TOC 7 Nov 2002 16:24:07 -0000 1.18 *************** *** 9,12 **** --- 9,15 ---- * {-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?-} *************** *** 14,18 **** * {-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?-} - * {-How can I use quoted SQL identifiers?@How can I use quoted SQL identifiers?-} * {-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?-} --- 17,20 ---- Index: faq.html =================================================================== RCS file: /cvsroot/hibernate/Hibernate/doc/faq.html,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** faq.html 5 Nov 2002 08:04:00 -0000 1.39 --- faq.html 7 Nov 2002 16:24:08 -0000 1.40 *************** *** 30,33 **** --- 30,36 ---- <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> *************** *** 35,39 **** <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="#How can I use quoted SQL identifiers?">How can I use quoted SQL identifiers?</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> --- 38,41 ---- *************** *** 126,129 **** --- 128,177 ---- </p> <!--End Section 3--> + <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"> + You <strong>must</strong> override <tt>equals()</tt> and <tt>hashCode()</tt> correctly on your composite identifier class. This is quite critical. + </p> + <!--End Section 3--> + <h4><a name="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></h4> + <p class="Body"> + It is actually surprisingly hard to get your implementation of <tt>equals()</tt> right when proxies are enabled. You must be prepared for the possibility that that a class instance is really a proxy for that class, so you can't access instance variables directly (use the accessors). + </p> + <p class="Body"> + And if you are using <tt><key-many-to-one></tt> you should compare entity equality by comparing identifiers instead of using <tt>==</tt>. + </p> + <!--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"> + This kind of mapping is unsupported: + </p> + <pre> + <class name="BalanceSheet"> + .... + <set role="purchases"> + <key ....> + <one-to-many class="Purchase" column="bsid"/> + </set> + <set role="sales"> + <key ....> + <one-to-many class="Sale" column="bsid"/> + </set> + </class> + </pre> + <pre> + <class name="Transaction"> + .... + <subclass name="Purchase".../> + <subclass name="Sale".../> + </class> + </pre> + <p class="Body"> + You must either + </p> + <ol> + <li> map each association to a different column of the <tt>Transaction</tt> table</li> + <li> map a single association and use a collection filter to retrieve instances of a particular subclass</li> + <li> use a table-per-concrete-class mapping strategy for the <tt>Transaction</tt> hierarchy</li> + </ol> + <!--End Section 3--> <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> *************** *** 163,171 **** <p class="Body"> you will find it quite well documented. - </p> - <!--End Section 3--> - <h4><a name="How can I use quoted SQL identifiers?">How can I use quoted SQL identifiers?</a></h4> - <p class="Body"> - You can't. Sorry. We will fix this at some stage.... </p> <!--End Section 3--> --- 211,214 ---- |
From: <one...@us...> - 2002-11-07 16:24:43
|
Update of /cvsroot/hibernate/Hibernate/doc/reference/html In directory usw-pr-cvs1:/tmp/cvs-serv26764/reference/html Modified Files: or-mapping.html Log Message: new faqs Index: or-mapping.html =================================================================== RCS file: /cvsroot/hibernate/Hibernate/doc/reference/html/or-mapping.html,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** or-mapping.html 5 Nov 2002 13:40:53 -0000 1.30 --- or-mapping.html 7 Nov 2002 16:24:09 -0000 1.31 *************** *** 226,233 **** </p></div><div class="sect2"><div class="titlepage"><div><h3 class="title"><a name="or-mapping-s1-4b"></a>4.1.5. composite-id</h3></div></div><pre class="programlisting"><composite-id name="propertyName" ! class="className" unsaved-value="any|none|null"> ! <key-property name="propertyName" type="typename"/> ...... </composite-id></pre><p> --- 226,234 ---- </p></div><div class="sect2"><div class="titlepage"><div><h3 class="title"><a name="or-mapping-s1-4b"></a>4.1.5. composite-id</h3></div></div><pre class="programlisting"><composite-id name="propertyName" ! class="ClassName" unsaved-value="any|none|null"> ! <key-property name="propertyName" type="typename" column="column_name"/> ! <key-many-to-one name="propertyName class="ClassName" column="column_name"/> ...... </composite-id></pre><p> *************** *** 240,243 **** --- 241,247 ---- <property name="dependent"/> </composite-id></pre><p> + Your persistent class <span class="emphasis"><em>must</em></span> override <tt>equals()</tt> + and <tt>hashCode()</tt> to implement composite identifier equality. + </p><p> Unfortunately, this approach to composite identifiers means that a persistent object is its own identifier. There is no convenient "handle" other than the object itself. *************** *** 503,507 **** </set> <joined-subclass name="eg.DomesticCat"> ! <key column="CAT_ID"/> <property name="name" type="string"/> </joined-subclass> --- 507,511 ---- </set> <joined-subclass name="eg.DomesticCat"> ! <key column="CAT"/> <property name="name" type="string"/> </joined-subclass> |
From: <one...@us...> - 2002-11-07 16:24:15
|
Update of /cvsroot/hibernate/Hibernate/doc/reference/src In directory usw-pr-cvs1:/tmp/cvs-serv26764/reference/src Modified Files: basic_or_mapping.xml Log Message: new faqs Index: basic_or_mapping.xml =================================================================== RCS file: /cvsroot/hibernate/Hibernate/doc/reference/src/basic_or_mapping.xml,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** basic_or_mapping.xml 5 Nov 2002 13:40:54 -0000 1.32 --- basic_or_mapping.xml 7 Nov 2002 16:24:11 -0000 1.33 *************** *** 409,416 **** <programlisting><![CDATA[<composite-id name="propertyName" ! class="className" unsaved-value="any|none|null"> ! <key-property name="propertyName" type="typename"/> ...... </composite-id>]]></programlisting> --- 409,417 ---- <programlisting><![CDATA[<composite-id name="propertyName" ! class="ClassName" unsaved-value="any|none|null"> ! <key-property name="propertyName" type="typename" column="column_name"/> ! <key-many-to-one name="propertyName class="ClassName" column="column_name"/> ...... </composite-id>]]></programlisting> *************** *** 427,430 **** --- 428,436 ---- <property name="dependent"/> </composite-id>]]></programlisting> + + <para> + Your persistent class <emphasis>must</emphasis> override <literal>equals()</literal> + and <literal>hashCode()</literal> to implement composite identifier equality. + </para> <para> |
From: <one...@us...> - 2002-11-07 16:24:14
|
Update of /cvsroot/hibernate/Hibernate/doc/reference/html_single In directory usw-pr-cvs1:/tmp/cvs-serv26764/reference/html_single Modified Files: index.html Log Message: new faqs Index: index.html =================================================================== RCS file: /cvsroot/hibernate/Hibernate/doc/reference/html_single/index.html,v retrieving revision 1.76 retrieving revision 1.77 diff -C2 -d -r1.76 -r1.77 *** index.html 5 Nov 2002 13:40:54 -0000 1.76 --- index.html 7 Nov 2002 16:24:09 -0000 1.77 *************** *** 761,768 **** </p></div><div class="sect2"><div class="titlepage"><div><h3 class="title"><a name="or-mapping-s1-4b"></a>4.1.5. composite-id</h3></div></div><pre class="programlisting"><composite-id name="propertyName" ! class="className" unsaved-value="any|none|null"> ! <key-property name="propertyName" type="typename"/> ...... </composite-id></pre><p> --- 761,769 ---- </p></div><div class="sect2"><div class="titlepage"><div><h3 class="title"><a name="or-mapping-s1-4b"></a>4.1.5. composite-id</h3></div></div><pre class="programlisting"><composite-id name="propertyName" ! class="ClassName" unsaved-value="any|none|null"> ! <key-property name="propertyName" type="typename" column="column_name"/> ! <key-many-to-one name="propertyName class="ClassName" column="column_name"/> ...... </composite-id></pre><p> *************** *** 775,778 **** --- 776,782 ---- <property name="dependent"/> </composite-id></pre><p> + Your persistent class <span class="emphasis"><em>must</em></span> override <tt>equals()</tt> + and <tt>hashCode()</tt> to implement composite identifier equality. + </p><p> Unfortunately, this approach to composite identifiers means that a persistent object is its own identifier. There is no convenient "handle" other than the object itself. *************** *** 1038,1042 **** </set> <joined-subclass name="eg.DomesticCat"> ! <key column="CAT_ID"/> <property name="name" type="string"/> </joined-subclass> --- 1042,1046 ---- </set> <joined-subclass name="eg.DomesticCat"> ! <key column="CAT"/> <property name="name" type="string"/> </joined-subclass> |
From: <one...@us...> - 2002-11-07 16:14:05
|
Update of /cvsroot/hibernate/Hibernate In directory usw-pr-cvs1:/tmp/cvs-serv26145 Modified Files: changelog.txt Log Message: updated changelog Index: changelog.txt =================================================================== RCS file: /cvsroot/hibernate/Hibernate/changelog.txt,v retrieving revision 1.259 retrieving revision 1.260 diff -C2 -d -r1.259 -r1.260 *** changelog.txt 5 Nov 2002 16:58:12 -0000 1.259 --- changelog.txt 7 Nov 2002 16:14:00 -0000 1.260 *************** *** 12,18 **** * finished work on normalized table mappings using <joined-subclass> declaration * deprecated hibernate-mapping.dtd in favor of hibernate-mapping-1.1.dtd ! * reworked unmapped class / interface query functionality, fixing several problems * removed deprecated methods * deprecated findIdentifiers() Changes in version 1.1.8 (30.10.2002) --- 12,20 ---- * finished work on normalized table mappings using <joined-subclass> declaration * deprecated hibernate-mapping.dtd in favor of hibernate-mapping-1.1.dtd ! * reworked unmapped class / interface / table-per-concrete-class query functionality, fixing several problems * removed deprecated methods * deprecated findIdentifiers() + * fixed some problems with embedded composite identifiers + * fixed a bug cascading deletes to one-to-one associations Changes in version 1.1.8 (30.10.2002) |
From: <one...@us...> - 2002-11-07 16:04:14
|
Update of /cvsroot/hibernate/Hibernate/cirrus/hibernate/impl In directory usw-pr-cvs1:/tmp/cvs-serv20516/cirrus/hibernate/impl Modified Files: SessionImpl.java Log Message: fixed a bug cascading deletes to one-to-one associations Index: SessionImpl.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/impl/SessionImpl.java,v retrieving revision 1.149 retrieving revision 1.150 diff -C2 -d -r1.149 -r1.150 *** SessionImpl.java 5 Nov 2002 16:58:14 -0000 1.149 --- SessionImpl.java 7 Nov 2002 16:04:08 -0000 1.150 *************** *** 742,746 **** Set oldNullifiables = null; ArrayList oldDeletions = null; ! if ( persister.hasCascades() && persister.hasCollections() ) { oldNullifiables = new HashSet(); //TODO: change to clone() oldNullifiables.addAll(nullifiables); --- 742,746 ---- Set oldNullifiables = null; ArrayList oldDeletions = null; ! if ( persister.hasCascades() /*&& persister.hasCascadeBeforeDelete()*/ ) { oldNullifiables = new HashSet(); //TODO: change to clone() oldNullifiables.addAll(nullifiables); *************** *** 767,771 **** //BEGIN YUCKINESS: ! if ( persister.hasCascades() && persister.hasCollections() ) { int start = deletions.size(); --- 767,771 ---- //BEGIN YUCKINESS: ! if ( persister.hasCascades() /*&& persister.hasCascadeBeforeDelete()*/ ) { int start = deletions.size(); |
From: <one...@us...> - 2002-11-07 11:33:52
|
Update of /cvsroot/hibernate/Hibernate/cirrus/hibernate/loader In directory usw-pr-cvs1:/tmp/cvs-serv1018/hibernate/loader Modified Files: Loader.java Log Message: improved handling of <key-many-to-many> in load process Index: Loader.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/loader/Loader.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** Loader.java 7 Nov 2002 10:10:59 -0000 1.25 --- Loader.java 7 Nov 2002 11:33:48 -0000 1.26 *************** *** 123,131 **** for ( int i=0; i<cols; i++ ) { ! keys[i] = getKeyFromResultSet( persisters[i], suffixes[i], rs, session ); } // this call is side-effecty ! Object[] row = getRow(rs, persisters, suffixes, keys, hydrate, optionalObject, optionalObjectKey, optionalID, session); for ( int i=0; i<cols; i++ ) { --- 123,131 ---- for ( int i=0; i<cols; i++ ) { ! keys[i] = getKeyFromResultSet( persisters[i], suffixes[i], (i==cols-1) ? optionalID : null, rs, session ); } // this call is side-effecty ! Object[] row = getRow(rs, persisters, suffixes, keys, hydrate, optionalObject, optionalObjectKey, session); for ( int i=0; i<cols; i++ ) { *************** *** 179,192 **** /** * Read a row of <tt>Key</tt>s from the <tt>ResultSet</tt> into the given array. Warning: this ! * method is side-effecty. */ ! private Key getKeyFromResultSet(Loadable persister, String suffix, ResultSet rs, SessionImplementor session) throws HibernateException, SQLException { ! //TODO: we can cache these on this object, from the constructor ! String[] keyColNames = StringHelper.suffix( persister.getIdentifierColumnNames(), suffix ); ! StringHelper.unQuoteInPlace(keyColNames); ! Serializable id = (Serializable) persister.getIdentifierType().nullSafeGet(rs, keyColNames, session, null); return ( id==null ) ? null : new Key( id, persister ); } --- 179,196 ---- /** * Read a row of <tt>Key</tt>s from the <tt>ResultSet</tt> into the given array. Warning: this ! * method is side-effecty. If an <tt>id</tt> is given, don't bother going to the <tt>ResultSet</tt>. */ ! private Key getKeyFromResultSet(Loadable persister, String suffix, Serializable id, ResultSet rs, SessionImplementor session) throws HibernateException, SQLException { ! ! if (id==null) { ! //TODO: we can cache these on this object, from the constructor ! String[] keyColNames = StringHelper.suffix( persister.getIdentifierColumnNames(), suffix ); ! StringHelper.unQuoteInPlace(keyColNames); ! id = (Serializable) persister.getIdentifierType().nullSafeGet(rs, keyColNames, session, null); ! } ! return ( id==null ) ? null : new Key( id, persister ); } *************** *** 206,210 **** Object optionalObject, Key optionalObjectKey, - Serializable optionalID, SessionImplementor session ) throws HibernateException, SQLException { --- 210,213 ---- *************** *** 246,256 **** } else { - Serializable idInstance = key.getIdentifier(); - //Warning: the following code forces optionalID to refer to the last column of results!!!! - if ( i==cols-1 && optionalID!=null && optionalID.equals(idInstance) ) { - idInstance = optionalID; - } // instantiate a new instance ! object = session.getFactory().getPersister(instanceClass).instantiate(idInstance); } --- 249,254 ---- } else { // instantiate a new instance ! object = session.getFactory().getPersister(instanceClass).instantiate( key.getIdentifier() ); } |
Update of /cvsroot/hibernate/Hibernate/cirrus/hibernate/test In directory usw-pr-cvs1:/tmp/cvs-serv1018/hibernate/test Modified Files: FooBarTest.java MasterDetailTest.java MoreStuff.java Stuff.hbm.xml Stuff.java Log Message: improved handling of <key-many-to-many> in load process Index: FooBarTest.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/test/FooBarTest.java,v retrieving revision 1.218 retrieving revision 1.219 diff -C2 -d -r1.218 -r1.219 *** FooBarTest.java 7 Nov 2002 10:10:59 -0000 1.218 --- FooBarTest.java 7 Nov 2002 11:33:49 -0000 1.219 *************** *** 89,92 **** --- 89,96 ---- FooProxy foo = (FooProxy) s.load(Foo.class, id); s.load(more, more); + t.commit(); + s.close(); + s = sessions.openSession(); + t = s.beginTransaction(); Stuff stuff = new Stuff(); stuff.setFoo(foo); *************** *** 97,101 **** assertTrue( stuff.getMoreStuff().getName().equals("More Stuff") ); s.delete( stuff.getMoreStuff() ); ! s.delete(foo); t.commit(); s.close(); --- 101,105 ---- assertTrue( stuff.getMoreStuff().getName().equals("More Stuff") ); s.delete( stuff.getMoreStuff() ); ! s.delete("from foo in class Foo"); t.commit(); s.close(); Index: MasterDetailTest.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/test/MasterDetailTest.java,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** MasterDetailTest.java 7 Nov 2002 10:10:59 -0000 1.39 --- MasterDetailTest.java 7 Nov 2002 11:33:49 -0000 1.40 *************** *** 50,53 **** --- 50,63 ---- t.commit(); s.close(); + s = sessions.openSession(); + t = s.beginTransaction(); + s.find("from s in class Several"); + t.commit(); + s.close(); + s = sessions.openSession(); + t = s.beginTransaction(); + s.find("from s in class Single"); + t.commit(); + s.close(); } Index: MoreStuff.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/test/MoreStuff.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MoreStuff.java 7 Nov 2002 10:12:15 -0000 1.1 --- MoreStuff.java 7 Nov 2002 11:33:49 -0000 1.2 *************** *** 11,14 **** --- 11,22 ---- private Collection stuffs; private String name; + + public boolean equals(Object other) { + return ( (MoreStuff) other ).getIntId()==intId && ( (MoreStuff) other ).getStringId().equals(stringId); + } + + public int hashCode() { + return stringId.hashCode(); + } /** Index: Stuff.hbm.xml =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/test/Stuff.hbm.xml,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Stuff.hbm.xml 7 Nov 2002 10:10:59 -0000 1.4 --- Stuff.hbm.xml 7 Nov 2002 11:33:49 -0000 1.5 *************** *** 23,31 **** <key-property name="id"/> <key-many-to-one name="foo" class="cirrus.hibernate.test.Foo"/> ! </composite-id> ! <many-to-one name="moreStuff" class="cirrus.hibernate.test.MoreStuff"> <column name="moreInt"/> <column name="moreString"/> ! </many-to-one> <property name="property"/> </class> --- 23,31 ---- <key-property name="id"/> <key-many-to-one name="foo" class="cirrus.hibernate.test.Foo"/> ! <key-many-to-one name="moreStuff" class="cirrus.hibernate.test.MoreStuff"> <column name="moreInt"/> <column name="moreString"/> ! </key-many-to-one> ! </composite-id> <property name="property"/> </class> Index: Stuff.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/test/Stuff.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Stuff.java 7 Nov 2002 10:10:59 -0000 1.2 --- Stuff.java 7 Nov 2002 11:33:49 -0000 1.3 *************** *** 14,18 **** if ( ! (other instanceof Stuff) ) return false; Stuff otherStuff = (Stuff) other; ! return otherStuff.id==id && otherStuff.foo==foo && otherStuff.moreStuff==moreStuff; } --- 14,18 ---- if ( ! (other instanceof Stuff) ) return false; Stuff otherStuff = (Stuff) other; ! return otherStuff.getId()==id && otherStuff.getFoo().getKey().equals( foo.getKey() ) && otherStuff.getMoreStuff().equals(moreStuff); } |
From: <one...@us...> - 2002-11-07 10:12:18
|
Update of /cvsroot/hibernate/Hibernate/cirrus/hibernate/test In directory usw-pr-cvs1:/tmp/cvs-serv25310/hibernate/test Added Files: MoreStuff.java Several.java Single.java SingleSeveral.hbm.xml Log Message: fixed a bug with embedded composite-ids and outerjoin fetching --- NEW FILE: MoreStuff.java --- //$Id: MoreStuff.java,v 1.1 2002/11/07 10:12:15 oneovthafew Exp $ package cirrus.hibernate.test; import java.io.Serializable; import java.util.Collection; public class MoreStuff implements Serializable { private String stringId; private int intId; private Collection stuffs; private String name; /** * Returns the stuffs. * @return Collection */ public Collection getStuffs() { return stuffs; } /** * Sets the stuffs. * @param stuffs The stuffs to set */ public void setStuffs(Collection stuffs) { this.stuffs = stuffs; } /** * Returns the name. * @return String */ public String getName() { return name; } /** * Sets the name. * @param name The name to set */ public void setName(String name) { this.name = name; } /** * Returns the intId. * @return int */ public int getIntId() { return intId; } /** * Returns the stringId. * @return String */ public String getStringId() { return stringId; } /** * Sets the intId. * @param intId The intId to set */ public void setIntId(int intId) { this.intId = intId; } /** * Sets the stringId. * @param stringId The stringId to set */ public void setStringId(String stringId) { this.stringId = stringId; } } --- NEW FILE: Several.java --- //$Id: Several.java,v 1.1 2002/11/07 10:12:15 oneovthafew Exp $ package cirrus.hibernate.test; import java.io.Serializable; public class Several implements Serializable { private String id; private String prop; private Single single; private String string; /** * Returns the id. * @return String */ public String getId() { return id; } /** * Returns the prop. * @return String */ public String getProp() { return prop; } /** * Returns the single. * @return Single */ public Single getSingle() { return single; } /** * Sets the id. * @param id The id to set */ public void setId(String id) { this.id = id; } /** * Sets the prop. * @param prop The prop to set */ public void setProp(String prop) { this.prop = prop; } /** * Sets the single. * @param single The single to set */ public void setSingle(Single single) { this.single = single; } /** * Returns the string. * @return String */ public String getString() { return string; } /** * Sets the string. * @param string The string to set */ public void setString(String string) { this.string = string; } public boolean equals(Object other) { return ( (Several) other ).id.equals(id) && ( (Several) other ).string.equals(string); } public int hashCode() { return id.hashCode(); } } --- NEW FILE: Single.java --- //$Id: Single.java,v 1.1 2002/11/07 10:12:15 oneovthafew Exp $ package cirrus.hibernate.test; import java.io.Serializable; import java.util.Collection; import java.util.HashSet; public class Single implements Serializable { private String id; private String prop; private String string; private Collection several = new HashSet(); /** * Returns the id. * @return String */ public String getId() { return id; } /** * Returns the prop. * @return String */ public String getProp() { return prop; } /** * Returns the several. * @return Set */ public Collection getSeveral() { return several; } /** * Sets the id. * @param id The id to set */ public void setId(String id) { this.id = id; } /** * Sets the prop. * @param prop The prop to set */ public void setProp(String prop) { this.prop = prop; } /** * Sets the several. * @param several The several to set */ public void setSeveral(Collection several) { this.several = several; } /** * Returns the string. * @return String */ public String getString() { return string; } /** * Sets the string. * @param string The string to set */ public void setString(String string) { this.string = string; } public boolean equals(Object other) { return ( (Single) other ).id.equals(id) && ( (Single) other ).string.equals(string); } public int hashCode() { return id.hashCode(); } } --- NEW FILE: SingleSeveral.hbm.xml --- <?xml version="1.0"?> <!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-1.1.dtd" > <hibernate-mapping> <class name="cirrus.hibernate.test.Single"> <composite-id> <key-property name="id"/> <key-property name="string"/> </composite-id> <property name="prop"/> <bag role="several" readonly="true" lazy="false" cascade="all"> <!--important: test for bidirectional with lazy="false" --> <key> <column name="single_id" not-null="true"/> <column name="single_string" not-null="true"/> </key> <one-to-many class="cirrus.hibernate.test.Several"/> </bag> </class> <class name="cirrus.hibernate.test.Several"> <composite-id> <key-property name="id"/> <key-property name="string"/> </composite-id> <many-to-one name="single"> <column name="single_id"/> <column name="single_string"/> </many-to-one> </class> </hibernate-mapping> |
From: <one...@us...> - 2002-11-07 10:11:03
|
Update of /cvsroot/hibernate/Hibernate/cirrus/hibernate/proxy In directory usw-pr-cvs1:/tmp/cvs-serv24773/hibernate/proxy Modified Files: CGLIBLazyInitializer.java Log Message: fixed a bug with embedded composite-ids and outerjoin fetching Index: CGLIBLazyInitializer.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/proxy/CGLIBLazyInitializer.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CGLIBLazyInitializer.java 2 Nov 2002 14:32:13 -0000 1.4 --- CGLIBLazyInitializer.java 7 Nov 2002 10:10:59 -0000 1.5 *************** *** 4,14 **** import java.io.Serializable; import java.lang.reflect.Method; import cirrus.hibernate.HibernateException; import cirrus.hibernate.engine.SessionImplementor; ! import net.sf.cglib.proxy.Enhancer; import net.sf.cglib.proxy.MethodInterceptor; /** * --- 4,17 ---- import java.io.Serializable; import java.lang.reflect.Method; + + import org.apache.commons.logging.LogFactory; import cirrus.hibernate.HibernateException; import cirrus.hibernate.engine.SessionImplementor; ! import net.sf.cglib.proxy.Enhancer; import net.sf.cglib.proxy.MethodInterceptor; + /** * *************** *** 28,31 **** --- 31,35 ---- } catch (Throwable t) { + LogFactory.getLog(LazyInitializer.class).error("CGLIB Enhancement failed", t); throw new HibernateException( "CGLIB Enhancement failed", t ); } |
From: <one...@us...> - 2002-11-07 10:11:03
|
Update of /cvsroot/hibernate/Hibernate/cirrus/hibernate/test In directory usw-pr-cvs1:/tmp/cvs-serv24773/hibernate/test Modified Files: FooBarTest.java MasterDetailTest.java Stuff.hbm.xml Stuff.java Log Message: fixed a bug with embedded composite-ids and outerjoin fetching Index: FooBarTest.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/test/FooBarTest.java,v retrieving revision 1.217 retrieving revision 1.218 diff -C2 -d -r1.217 -r1.218 *** FooBarTest.java 5 Nov 2002 16:58:14 -0000 1.217 --- FooBarTest.java 7 Nov 2002 10:10:59 -0000 1.218 *************** *** 50,53 **** --- 50,106 ---- } + public void testAssociationId() throws Exception { + Session s = sessions.openSession(); + Transaction t = s.beginTransaction(); + Bar bar = new Bar(); + String id = (String) s.save(bar); + MoreStuff more = new MoreStuff(); + more.setName("More Stuff"); + more.setIntId(12); + more.setStringId("id"); + Stuff stuf = new Stuff(); + stuf.setMoreStuff(more); + more.setStuffs( new ArrayList() ); + more.getStuffs().add(stuf); + stuf.setFoo(bar); + stuf.setId(1234); + stuf.setProperty( TimeZone.getDefault() ); + s.save(more); + t.commit(); + s.close(); + + s = sessions.openSession(); + t = s.beginTransaction(); + assertTrue( s.find( + "from s in class Stuff where s.foo.id = ? and s.id.id = ? and s.moreStuff.id.intId = ? and s.moreStuff.id.stringId = ?", + new Object[] { bar, new Long(1234), new Integer(12), "id" }, + new Type[] { Hibernate.association(Foo.class), Hibernate.LONG, Hibernate.INTEGER, Hibernate.STRING } + ).size()==1 ); + assertTrue( s.find( + "from s in class Stuff where s.foo.id = ? and s.id.id = ? and s.moreStuff.name = ?", + new Object[] { bar, new Long(1234), "More Stuff" }, + new Type[] { Hibernate.association(Foo.class), Hibernate.LONG, Hibernate.STRING } + ).size()==1 ); + s.find("from s in class Stuff where s.foo.string is not null"); + t.commit(); + s.close(); + s = sessions.openSession(); + t = s.beginTransaction(); + FooProxy foo = (FooProxy) s.load(Foo.class, id); + s.load(more, more); + Stuff stuff = new Stuff(); + stuff.setFoo(foo); + stuff.setId(1234); + stuff.setMoreStuff(more); + s.load(stuff, stuff); + assertTrue( stuff.getProperty().equals( TimeZone.getDefault() ) ); + assertTrue( stuff.getMoreStuff().getName().equals("More Stuff") ); + s.delete( stuff.getMoreStuff() ); + s.delete(foo); + t.commit(); + s.close(); + } + + public void testCompositeKeyPathExpressions() throws Exception { Session s = sessions.openSession(); *************** *** 2625,2664 **** } - public void testAssociationId() throws Exception { - Session s = sessions.openSession(); - Transaction t = s.beginTransaction(); - Bar bar = new Bar(); - String id = (String) s.save(bar); - Stuff stuf = new Stuff(); - stuf.setFoo(bar); - stuf.setId(1234); - stuf.setProperty( TimeZone.getDefault() ); - s.save(stuf); - t.commit(); - s.close(); - s = sessions.openSession(); - t = s.beginTransaction(); - assertTrue( - s.find("from s in class Stuff where s.foo.id = ? and s.id.id = ?", - new Object[] { bar, new Long(1234) }, new Type[] { Hibernate.association(Foo.class), Hibernate.LONG } ) - .size()==1 ); - s.find("from s in class Stuff where s.foo.string is not null"); - t.commit(); - s.close(); - s = sessions.openSession(); - t = s.beginTransaction(); - FooProxy foo = (FooProxy) s.load(Foo.class, id); - Stuff stuff = new Stuff(); - stuff.setFoo(foo); - stuff.setId(1234); - s.load(stuff, stuff); - assertTrue( stuff.getProperty().equals( TimeZone.getDefault() ) ); - s.delete(stuff); - s.delete(foo); - t.commit(); - s.close(); - } - - public static Test suite() throws Exception { try { --- 2678,2681 ---- Index: MasterDetailTest.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/test/MasterDetailTest.java,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** MasterDetailTest.java 5 Nov 2002 16:58:14 -0000 1.38 --- MasterDetailTest.java 7 Nov 2002 10:10:59 -0000 1.39 *************** *** 26,29 **** --- 26,55 ---- } + public void testNonLazyBidirectional() throws Exception { + Session s = sessions.openSession(); + Transaction t = s.beginTransaction(); + Single sin = new Single(); + sin.setId("asdfds"); + sin.setString("adsa asdfasd"); + Several sev = new Several(); + sev.setId("asdfasdfasd"); + sev.setString("asd ddd"); + sin.getSeveral().add(sev); + sev.setSingle(sin); + s.save(sin); + t.commit(); + s.close(); + s = sessions.openSession(); + t = s.beginTransaction(); + sin = (Single) s.load( Single.class, sin ); + t.commit(); + s.close(); + s = sessions.openSession(); + t = s.beginTransaction(); + sev = (Several) s.load( Several.class, sev ); + t.commit(); + s.close(); + } + public void testCollectionQuery() throws Exception { Session s = sessions.openSession(); *************** *** 431,439 **** s.close(); } ! public static Test suite() throws Exception { TestCase.exportSchema( ! new String[] { "MasterDetail.hbm.xml", "Custom.hbm.xml", "Category.hbm.xml", "Nameable.hbm.xml" } ); return new TestSuite(MasterDetailTest.class); --- 457,465 ---- s.close(); } ! public static Test suite() throws Exception { TestCase.exportSchema( ! new String[] { "MasterDetail.hbm.xml", "Custom.hbm.xml", "Category.hbm.xml", "Nameable.hbm.xml", "SingleSeveral.hbm.xml" } ); return new TestSuite(MasterDetailTest.class); Index: Stuff.hbm.xml =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/test/Stuff.hbm.xml,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Stuff.hbm.xml 7 Oct 2002 18:08:46 -0000 1.3 --- Stuff.hbm.xml 7 Nov 2002 10:10:59 -0000 1.4 *************** *** 2,6 **** <!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-1.1.dtd" > <hibernate-mapping> ! <class name="cirrus.hibernate.test.Stuff"> <composite-id> --- 2,22 ---- <!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-1.1.dtd" > <hibernate-mapping> ! ! <class name="cirrus.hibernate.test.MoreStuff"> ! <composite-id> ! <key-property name="intId"/> ! <key-property name="stringId"/> ! </composite-id> ! <property name="name"/> ! <bag role="stuffs" readonly="true" lazy="false" cascade="all"> ! <key> ! <!--unfortunately have to specify not-null here because of limitation in schema export....--> ! <column name="moreInt" not-null="true"/> ! <column name="moreString" not-null="true"/> ! </key> ! <one-to-many class="cirrus.hibernate.test.Stuff"/> ! </bag> ! </class> ! <class name="cirrus.hibernate.test.Stuff"> <composite-id> *************** *** 8,11 **** --- 24,31 ---- <key-many-to-one name="foo" class="cirrus.hibernate.test.Foo"/> </composite-id> + <many-to-one name="moreStuff" class="cirrus.hibernate.test.MoreStuff"> + <column name="moreInt"/> + <column name="moreString"/> + </many-to-one> <property name="property"/> </class> Index: Stuff.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/test/Stuff.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Stuff.java 5 Oct 2002 18:07:50 -0000 1.1 --- Stuff.java 7 Nov 2002 10:10:59 -0000 1.2 *************** *** 14,22 **** if ( ! (other instanceof Stuff) ) return false; Stuff otherStuff = (Stuff) other; ! return otherStuff.id==id && otherStuff.foo==foo; } private long id; private FooProxy foo; private TimeZone property; /** --- 14,23 ---- if ( ! (other instanceof Stuff) ) return false; Stuff otherStuff = (Stuff) other; ! return otherStuff.id==id && otherStuff.foo==foo && otherStuff.moreStuff==moreStuff; } private long id; private FooProxy foo; + private MoreStuff moreStuff; private TimeZone property; /** *************** *** 66,69 **** --- 67,86 ---- public void setProperty(TimeZone property) { this.property = property; + } + + /** + * Returns the moreStuff. + * @return MoreStuff + */ + public MoreStuff getMoreStuff() { + return moreStuff; + } + + /** + * Sets the moreStuff. + * @param moreStuff The moreStuff to set + */ + public void setMoreStuff(MoreStuff moreStuff) { + this.moreStuff = moreStuff; } |
From: <one...@us...> - 2002-11-07 10:11:03
|
Update of /cvsroot/hibernate/Hibernate/cirrus/hibernate/loader In directory usw-pr-cvs1:/tmp/cvs-serv24773/hibernate/loader Modified Files: Loader.java Log Message: fixed a bug with embedded composite-ids and outerjoin fetching Index: Loader.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/loader/Loader.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** Loader.java 4 Nov 2002 08:10:49 -0000 1.24 --- Loader.java 7 Nov 2002 10:10:59 -0000 1.25 *************** *** 240,246 **** if ( optionalObjectKey!=null && key.equals(optionalObjectKey) ) { - //if ( instanceClass != optionalObject.getClass() ) - //throw new WrongClassException( "given object of was wrong subclass", key.getIdentifier(), instanceClass ); - //its the given optional object object=optionalObject; --- 240,243 ---- *************** *** 249,256 **** } else { // instantiate a new instance ! object = session.getFactory().getPersister(instanceClass).instantiate( ! (optionalID==null) ? key.getIdentifier() : optionalID ! ); } --- 246,256 ---- } else { + Serializable idInstance = key.getIdentifier(); + //Warning: the following code forces optionalID to refer to the last column of results!!!! + if ( i==cols-1 && optionalID!=null && optionalID.equals(idInstance) ) { + idInstance = optionalID; + } // instantiate a new instance ! object = session.getFactory().getPersister(instanceClass).instantiate(idInstance); } |