-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 posts ] 
Author Message
 Post subject: Does a one-to-manyrelationship have to be bidirectional?
PostPosted: Tue Oct 07, 2003 9:53 am 
Newbie

Joined: Tue Oct 07, 2003 9:43 am
Posts: 16
Location: Chicago
I have been trying to get a simple one-to-many relationship to work. I have a Vendor that can have many contacts. So when I do Vendor.save() it should automatically persist the multiple contacts.

Firstly is this possible? Do I have to use bidirectional? Please advise.

Below are my mappings for vendor and contact respectively:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
    <class name="com.poc.Vendor" table="TEST_VENDOR">
       <id name="vendorID" column="VENDORID">
           <generator class="foreign">
            <param name="property">address</param>
           </generator>
        </id>
        <property name="name" column="VENDORNAME"/>
        <bag name="contacts" cascade="all">
           <key column="VENDORID"/>
           <one-to-many class="com.poc.Contact"/>
          </bag>
    </class>
</hibernate-mapping>

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
    <class name="com.poc.Contact" table="TEST_CONTACT">
        <id name="contactID" column="CONTACTID">
           <generator class="assigned"/>
        </id>
        <property name="name" column="CONTACTNAME"/>
        <property name="phone" column="CONTACTPHONE"/>
    </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2003 9:55 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Your mapping is good, what is the problem? Have you read the Hibernate reference documentation, chapter "Parent/child relationship"?

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: I get the following error
PostPosted: Tue Oct 07, 2003 10:07 am 
Newbie

Joined: Tue Oct 07, 2003 9:43 am
Posts: 16
Location: Chicago
Below is the error that I get when I am trying to persist a Vendor with multiple contacts:

Quote:
INFO: Use scrollable result sets: false
Oct 7, 2003 10:03:02 AM net.sf.hibernate.impl.SessionFactoryImpl <init>
INFO: JDBC 2 max batch size: 15
Oct 7, 2003 10:03:04 AM net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: no JDNI name configured
Oct 7, 2003 10:03:04 AM net.sf.hibernate.impl.SessionFactoryImpl <init>
INFO: Query language substitutions: {}
<Oct 7, 2003 10:03:04 AM EDT> <Error> <HTTP> <BEA-101017> <[ServletContext(id=1073441,name=poc,context-path=/p
java.lang.NoClassDefFoundError: org/odmg/DCollection
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:502)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:250)
at java.net.URLClassLoader.access$100(URLClassLoader.java:54)
at java.net.URLClassLoader$1.run(URLClassLoader.java:193)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:502)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:250)
at java.net.URLClassLoader.access$100(URLClassLoader.java:54)
at java.net.URLClassLoader$1.run(URLClassLoader.java:193)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
at net.sf.hibernate.type.BagType.wrap(BagType.java:31)
at net.sf.hibernate.impl.SessionImpl.wrap(SessionImpl.java:2519)
at net.sf.hibernate.impl.SessionImpl.wrap(SessionImpl.java:2459)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:708)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:605)
at com.poc.BaseDAO.addVendor(BaseDAO.java:61)
at jsp_servlet.__page5._jspService(__page5.java:196)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1053)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:387)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:431)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.jav
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3622)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2569)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)


Also here is the code for saving vendor:
Code:
public void configure() throws HibernateException {
      //Properties hProp = new Properties();
      //hProp.put("hibernate.connection.driver_class","oracle.jdbc.driver.OracleDriver");
      //hProp.put("hibernate.connection.url","jdbc:oracle:thin:@localhost:1521:JONE");
      //hProp.put("hibernate.connection.username","ep10");
      //hProp.put("hibernate.connection.password","ep10");
      //hProp.put("hibernate.dialect","net.sf.hibernate.dialect.Oracle9Dialect");
      
      sessionFactory =
         new Configuration()
            .addClass(Vendor.class)
            .addClass(Contact.class)
            .buildSessionFactory();
   }

Code:
public boolean addVendor(Vendor vendor) throws HibernateException {
      boolean result = false;

      Session session = sessionFactory.openSession();

      try {
         session.save(vendor);
         session.flush();
         result = true;
         session.connection().commit();
         session.close();
         
      } catch (HibernateException he) {
         result = false;
         throw he;
      } catch (SQLException sqe){
         result = false;
      }
      return result;
   }


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2003 10:09 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Well, a "Class not found" error would suggest a class is not found by the classloader. In your case, you didn't copy the odmg.jar from the distribution into your library directory. Please read the Quickstart Tutorial in the Hibernate examples or check the "VERSIONS" file in the lib/ directory.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: That worked, but Contacts does not get persisted in the DB
PostPosted: Tue Oct 07, 2003 10:32 am 
Newbie

Joined: Tue Oct 07, 2003 9:43 am
Posts: 16
Location: Chicago
Following your advise I no longer get the "Class not found" error. In fact I get no errors but the contacts do not get persisted in the Database.

Do I have to explicitly call Contacts.save()?

Below is the code in the JSP for calling the addVendor method:
Code:
//Vendor Attributes
   String vendorID = "222";
   String vendorName = "testing!!!!";

   //Contact 1 Attribtues
   String cId = "1";
   String cName = "abc";
   String cPhone = "1234567890";

   //Contact 2 Attribtues
   String cId2 = "2";
   String cName2 = "xyz";
   String cPhone2 = "5555555555";

   //set Contact persistible classes.
   Contact c1 = new Contact();
   c1.setContactID(cId);
   c1.setName(cName);
   c1.setPhone(cPhone);

   Contact c2 = new Contact();
   c2.setContactID(cId2);
   c2.setName(cName2);
   c2.setPhone(cPhone2);

   // Add a list of Contacts
        List contacts = new LinkedList();
        contacts = new ArrayList();
        contacts.add(c1);
   contacts.add(c2);


   //set the Vendor persistible class.
   Vendor vendor = new Vendor();
   vendor.setVendorID(vendorID);
   vendor.setName(vendorName);
   vendor.setContacts(contacts);

   //Instantiate the DAO.
   BaseDAO dao = new BaseDAO();
   dao.configure();
   boolean result = dao.addVendor(vendor);


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2003 10:46 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Eh, the Contacts should be saved by cascading "all" operations on this association mapping. Your code is good, but I guess you have an "assigned" identifer on the Vendor mapping, not a "foreign"? Otherwise, check the Hibernate log at debug level.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: how do i enable logging in HB?
PostPosted: Tue Oct 07, 2003 11:53 am 
Newbie

Joined: Tue Oct 07, 2003 9:43 am
Posts: 16
Location: Chicago
I already have logging enabled in WLS and get the info messages from HB. How do I enable detailed logging in HB.

Also I am using the foreign id generator for Vendor as I have a one-to-one relationship with Address apart from having a one-to-many relationship with contacts.

I had intentionally left out the address mappings. But it could be the source of the porblem?

Both Vendor and Address get persisted into the DB except for Contacts.

Vendor Mapping:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
    <class name="com.poc.Vendor" table="TEST_VENDOR">
       <id name="vendorID" column="VENDORID">
           <generator class="foreign">
            <param name="property">address</param>
           </generator>
        </id>
        <property name="name" column="VENDORNAME"/>
        <one-to-one name="address" class="com.poc.Address"/>
        <bag name="contacts" cascade="all">
           <key column="VENDORID"/>
           <one-to-many class="com.poc.Contact"/>
          </bag>
    </class>
</hibernate-mapping>

Contact Mapping:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
    <class name="com.poc.Contact" table="TEST_CONTACT">
        <id name="contactID" column="CONTACTID">
           <generator class="assigned"/>
        </id>
        <property name="name" column="CONTACTNAME"/>
        <property name="phone" column="CONTACTPHONE"/>
    </class>
</hibernate-mapping>

Address Mapping:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
    <class name="com.poc.Address" table="TEST_ADDRESS">
        <id name="vendorID" column="VENDORID" unsaved-value="null">
           <generator class="assigned"/>
        </id>
        <property name="city" column="CITY"/>
        <property name="country" column="COUNTRY"/>
        <property name="line1" column="LINE1"/>
        <property name="line2" column="LINE2"/>
        <property name="state" column="STATE"/>
        <property name="zip" column="ZIP"/>
    </class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2003 11:58 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Place the example log4j.properties in your application classpath and add log4j.jar. Check the properties.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: here is the log
PostPosted: Tue Oct 07, 2003 12:42 pm 
Newbie

Joined: Tue Oct 07, 2003 9:43 am
Posts: 16
Location: Chicago
I did as told and got the following log:
Code:
12:40:23,438  INFO Environment:403 - Hibernate 2.0.3
12:40:23,458  INFO Environment:437 - loaded properties from resource hibernate.properties: {hibernate.connection.username=ep10, hibernate.connection.password=ep10
12:40:23,468  INFO Environment:452 - using CGLIB reflection optimizer
12:40:23,468  INFO Environment:462 - JVM proxy support: true
12:40:23,478  INFO Configuration:283 - Mapping resource: com/poc/Vendor.hbm.xml
12:40:23,588  INFO Binder:178 - Mapping class: com.poc.Vendor -> TEST_VENDOR
12:40:24,229  INFO Configuration:283 - Mapping resource: com/poc/Address.hbm.xml
12:40:24,269  INFO Binder:178 - Mapping class: com.poc.Address -> TEST_ADDRESS
12:40:24,279  INFO Configuration:283 - Mapping resource: com/poc/Contact.hbm.xml
12:40:24,330  INFO Binder:178 - Mapping class: com.poc.Contact -> TEST_CONTACT
12:40:24,340  INFO Configuration:492 - processing one-to-many association mappings
12:40:24,340  INFO Binder:1025 - Mapping collection: com.poc.Vendor.contacts -> TEST_CONTACT
12:40:24,360  INFO Configuration:503 - processing foreign key constraints
12:40:24,450  INFO SessionFactoryImpl:132 - building session factory
12:40:24,470  INFO Dialect:83 - Using dialect: net.sf.hibernate.dialect.Oracle9Dialect
12:40:24,480  INFO DriverManagerConnectionProvider:41 - Hibernate connection pool size: 20
12:40:24,490  INFO DriverManagerConnectionProvider:70 - using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:thin:@localhost:1521:JONE
12:40:24,490  INFO DriverManagerConnectionProvider:71 - connection properties: {user=ep10, password=ep10}
12:40:24,500  INFO SessionFactoryImpl:162 - Use outer join fetching: true
12:40:24,740  INFO SessionFactoryImpl:185 - Use scrollable result sets: true
12:40:24,740  INFO SessionFactoryImpl:186 - JDBC 2 max batch size: 15
12:40:25,071  INFO SessionFactoryObjectFactory:82 - no JDNI name configured
12:40:25,071  INFO SessionFactoryImpl:269 - Query language substitutions: {}


Top
 Profile  
 
 Post subject: Sorry! My bad here are the debug level logs
PostPosted: Tue Oct 07, 2003 12:55 pm 
Newbie

Joined: Tue Oct 07, 2003 9:43 am
Posts: 16
Location: Chicago
Sorry, forgot to turn on the debug level!

Below are the debug level messages:

Code:
12:50:24,132 DEBUG SessionFactoryImpl:281 - instantiated session factory
12:50:24,132 DEBUG SessionImpl:413 - opened session
12:50:24,142 DEBUG SessionImpl:656 - saving [com.poc.Address#004]
12:50:24,142 DEBUG SessionImpl:656 - saving [com.poc.Vendor#004]
12:50:24,142 DEBUG Cascades:336 - processing cascades for: com.poc.Vendor
12:50:24,142 DEBUG Cascades:344 - done processing cascades for: com.poc.Vendor
12:50:24,142 DEBUG SessionImpl:2520 - Wrapped collection in role: com.poc.Vendor.contacts
12:50:24,142 DEBUG Cascades:336 - processing cascades for: com.poc.Vendor
12:50:24,142 DEBUG Cascades:275 - cascading to collection: com.poc.Vendor.contacts
12:50:24,142 DEBUG Cascades:87 - cascading to saveOrUpdate()
12:50:24,142 DEBUG Cascades:237 - unsaved-value strategy NULL
12:50:24,142 DEBUG SessionImpl:1205 - saveOrUpdate() previously saved instance with id: 1
12:50:24,142 DEBUG SessionImpl:1270 - updating [com.poc.Contact#1]
12:50:24,142 DEBUG Cascades:87 - cascading to saveOrUpdate()
12:50:24,152 DEBUG Cascades:237 - unsaved-value strategy NULL
12:50:24,152 DEBUG SessionImpl:1205 - saveOrUpdate() previously saved instance with id: 2
12:50:24,152 DEBUG SessionImpl:1270 - updating [com.poc.Contact#2]
12:50:24,152 DEBUG Cascades:344 - done processing cascades for: com.poc.Vendor
12:50:24,152 DEBUG SessionImpl:2011 - flushing session
12:50:24,152 DEBUG Cascades:336 - processing cascades for: com.poc.Vendor
12:50:24,152 DEBUG Cascades:275 - cascading to collection: com.poc.Vendor.contacts
12:50:24,152 DEBUG Cascades:87 - cascading to saveOrUpdate()
12:50:24,162 DEBUG SessionImpl:1183 - saveOrUpdate() persistent instance
12:50:24,162 DEBUG Cascades:87 - cascading to saveOrUpdate()
12:50:24,162 DEBUG SessionImpl:1183 - saveOrUpdate() persistent instance
12:50:24,162 DEBUG Cascades:344 - done processing cascades for: com.poc.Vendor
12:50:24,162 DEBUG SessionImpl:2113 - Flushing entities and processing referenced collections
12:50:24,162 DEBUG SessionImpl:2550 - Collection found: [com.poc.Vendor.contacts#004], was: [<unreferenced>]
12:50:24,172 DEBUG SessionImpl:2209 - Updating entity: [com.poc.Contact#1]
12:50:24,172 DEBUG SessionImpl:2209 - Updating entity: [com.poc.Contact#2]
12:50:24,172 DEBUG SessionImpl:2397 - Processing unreferenced collections
12:50:24,172 DEBUG SessionImpl:2408 - Scheduling collection removes/(re)creates/updates
12:50:24,172 DEBUG SessionImpl:2023 - Flushed: 2 insertions, 2 updates, 0 deletions to 4 objects
12:50:24,172 DEBUG SessionImpl:2028 - Flushed: 1 (re)creations, 0 updates, 0 removals to 1 collections
12:50:24,172 DEBUG SessionImpl:2058 - executing flush
12:50:24,172 DEBUG EntityPersister:464 - Inserting entity: com.poc.Address#004
12:50:24,172 DEBUG BatcherImpl:166 - about to open: 0 open PreparedStatements, 0 open ResultSets
12:50:24,172 DEBUG DriverManagerConnectionProvider:77 - total checked-out connections: 0
12:50:24,172 DEBUG DriverManagerConnectionProvider:83 - using pooled JDBC connection, pool size: 0
12:50:24,172 DEBUG SessionFactoryImpl:526 - prepared statement get: insert into TEST_ADDRESS (CITY, COUNTRY, LINE1, LINE2, STATE, ZIP, VENDORID) values
12:50:24,182 DEBUG SessionFactoryImpl:536 - preparing statement
12:50:24,182 DEBUG EntityPersister:366 - Dehydrating entity: com.poc.Address#004
12:50:24,182 DEBUG BatcherImpl:24 - Adding to batch
12:50:24,182 DEBUG EntityPersister:464 - Inserting entity: com.poc.Vendor#004
12:50:24,182 DEBUG BatcherImpl:46 - Executing batch size: 1
12:50:24,182 DEBUG BatcherImpl:173 - done closing: 0 open PreparedStatements, 0 open ResultSets
12:50:24,182 DEBUG SessionFactoryImpl:554 - closing statement
12:50:24,192 DEBUG BatcherImpl:166 - about to open: 0 open PreparedStatements, 0 open ResultSets
12:50:24,192 DEBUG SessionFactoryImpl:526 - prepared statement get: insert into TEST_VENDOR (VENDORNAME, VENDORID) values (?, ?)
12:50:24,192 DEBUG SessionFactoryImpl:536 - preparing statement
12:50:24,192 DEBUG EntityPersister:366 - Dehydrating entity: com.poc.Vendor#004
12:50:24,192 DEBUG BatcherImpl:24 - Adding to batch
12:50:24,192 DEBUG BatcherImpl:46 - Executing batch size: 1
12:50:24,202 DEBUG BatcherImpl:173 - done closing: 0 open PreparedStatements, 0 open ResultSets
12:50:24,202 DEBUG SessionFactoryImpl:554 - closing statement
12:50:24,202 DEBUG EntityPersister:617 - Updating entity: com.poc.Contact#1
12:50:24,202 DEBUG BatcherImpl:166 - about to open: 0 open PreparedStatements, 0 open ResultSets
12:50:24,202 DEBUG SessionFactoryImpl:526 - prepared statement get: update TEST_CONTACT set CONTACTNAME=?, CONTACTPHONE=? where CONTACTID=?
12:50:24,202 DEBUG SessionFactoryImpl:536 - preparing statement
12:50:24,202 DEBUG EntityPersister:366 - Dehydrating entity: com.poc.Contact#1
12:50:24,202 DEBUG BatcherImpl:24 - Adding to batch
12:50:24,202 DEBUG EntityPersister:617 - Updating entity: com.poc.Contact#2
12:50:24,202 DEBUG EntityPersister:366 - Dehydrating entity: com.poc.Contact#2
12:50:24,212 DEBUG BatcherImpl:24 - Adding to batch
12:50:24,212 DEBUG BatcherImpl:46 - Executing batch size: 2
12:50:24,212 DEBUG BatcherImpl:173 - done closing: 0 open PreparedStatements, 0 open ResultSets
12:50:24,212 DEBUG SessionFactoryImpl:554 - closing statement
12:50:24,212 DEBUG CollectionPersister:617 - Inserting collection: com.poc.Vendor.contacts#004
12:50:24,222 DEBUG BatcherImpl:166 - about to open: 0 open PreparedStatements, 0 open ResultSets
12:50:24,222 DEBUG SessionFactoryImpl:526 - prepared statement get: update TEST_CONTACT set VENDORID=? where CONTACTID=?
12:50:24,222 DEBUG SessionFactoryImpl:536 - preparing statement
12:50:24,222 DEBUG BatcherImpl:24 - Adding to batch
12:50:24,222 DEBUG BatcherImpl:24 - Adding to batch
12:50:24,222 DEBUG CollectionPersister:643 - done inserting collection
12:50:24,222 DEBUG BatcherImpl:46 - Executing batch size: 2
12:50:24,232 DEBUG BatcherImpl:173 - done closing: 0 open PreparedStatements, 0 open ResultSets
12:50:24,232 DEBUG SessionFactoryImpl:554 - closing statement
12:50:24,232 DEBUG SessionImpl:2428 - post flush
12:50:24,232 DEBUG SessionImpl:435 - closing session
12:50:24,232 DEBUG SessionImpl:2930 - disconnecting session
12:50:24,232 DEBUG DriverManagerConnectionProvider:117 - returning connection to pool, pool size: 1
12:50:24,232 DEBUG SessionImpl:447 - transaction completion


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2003 1:01 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Ah. It tries to update the Contact instead of INSERT. I'm currently not sure what you have to do with assigned identifiers (I assume implementing an Interceptor...) because I'm right now active in a very different area of Hibernate. Steve should be able to answer that immediately.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2003 2:43 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
With assigned identifiers you pretty much have two viable approaches:
1) leave the mapping as-is (using the default unsaved-value of "null"), in which case Hibernate will assume all the associations are for update. Then you need to explicitly call session.save() on any new instances.
2) Implement a generator class which "doles out" your assigned identifiers. That way you can ties into the normal Hibernate instance management mechanisms. Whether of not you can do this depends on your app setup.

You could also utilize the Interceptor.isUnsaved() method to tell hibernate whether a particular instance is yet existent in the DB.

My advice... Avoid the "assigned" generation strategy if you can. A custom generator class implementation is a viable alternative to not use the "assigned" id-generation strategy, while still allowing you to manage your ids however you want.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.