-->
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.  [ 2 posts ] 
Author Message
 Post subject: Only part of Row being saved to DB
PostPosted: Tue Jun 15, 2004 12:00 am 
Beginner
Beginner

Joined: Fri Jun 04, 2004 12:50 pm
Posts: 32
Hi all,

I am trying to save an object to the database. I print out the object before trying to save it and all the information is displayed. But, after inserting it into the database the only field that gets saved is the id that gets created when adding the record. So, I have an empty record that has just an id.

The bottom of the log file shows the insert commands which I think are obviously incorrect.

Hibernate 2.1.3
Postgresql 7.4

Any help appreciated.

Cheers

Tom

Here is the java code:

try {
// 1. Fire up Hibernate
Configuration cfg = new Configuration()
.addClass(Family.class)
.addClass(Camper.class);
SessionFactory sf = cfg.buildSessionFactory();

System.out.println("This is the family being added to the DB: "+_family);
// 2. Open Session
Session sess = sf.openSession();

// 3. Save Product and close Session
Transaction t = sess.beginTransaction();
sess.save(_family);
t.commit();
sess.close();
} catch (MappingException me) {
me.printStackTrace();
} catch (HibernateException he) {
he.printStackTrace();
}

Here is the hbm.xml file

<class name="com.camp.common.family.Family" table="tblFamily">

<id name="familyID" type="integer">
<column name="id_family" sql-type="integer" not-null="true"/>
<generator class="sequence">
<param name="sequence">tblfamily_id_family_seq</param>
</generator>
</id>

<property name="parentOneTitle" insert="false" update="false">
<column name="p1_title" sql-type="char(16)" not-null="false"/>
</property>

<property name="parentOneLastName" insert="false" update="false">
<column name="p1_last_name" sql-type="char(64)" not-null="true"/>
</property>

<property name="parentOneFirstName" insert="false" update="false">
<column name="p1_first_name" sql-type="char(64)" not-null="true"/>
</property>

<set name="campers" lazy="false">
<key column="fk_id_family"/>
<one-to-many class="com.camp.common.camper.Camper"/>
</set>

</class>

Here is the log of the transaction

21:13:15,965 INFO [Configuration] Mapping resource: com/camp/common/family/Family.hbm.xml
21:13:16,022 INFO [Binder] Mapping class: com.camp.common.family.Family -> tblFamily
21:13:16,049 INFO [Configuration] Mapping resource: com/camp/common/camper/Camper.hbm.xml
21:13:16,070 INFO [Binder] Mapping class: com.camp.common.camper.Camper -> tblCamper
21:13:16,071 INFO [Configuration] processing one-to-many association mappings
21:13:16,072 INFO [Binder] Mapping collection: com.camp.common.family.Family.campers -> tblCamper
21:13:16,073 INFO [Configuration] processing one-to-one association property references
21:13:16,073 INFO [Configuration] processing foreign key constraints
21:13:16,076 INFO [Dialect] Using dialect: net.sf.hibernate.dialect.PostgreSQLDialect
21:13:16,077 INFO [SettingsFactory] Use outer join fetching: true
21:13:16,078 INFO [DriverManagerConnectionProvider] Using Hibernate built-in connection pool (not for production use!)
21:13:16,078 INFO [DriverManagerConnectionProvider] Hibernate connection pool size: 20
21:13:16,079 INFO [DriverManagerConnectionProvider] using driver: org.postgresql.Driver at URL: jdbc:postgresql://localhost/camp
21:13:16,080 INFO [DriverManagerConnectionProvider] connection properties: {user=postgres, password=}
21:13:16,081 INFO [TransactionManagerLookupFactory] No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
21:13:16,108 INFO [SettingsFactory] Use scrollable result sets: true
21:13:16,109 INFO [SettingsFactory] Use JDBC3 getGeneratedKeys(): false
21:13:16,110 INFO [SettingsFactory] Optimize cache for minimal puts: false
21:13:16,110 INFO [SettingsFactory] echoing all SQL to stdout
21:13:16,111 INFO [SettingsFactory] Query language substitutions: {}
21:13:16,111 INFO [SettingsFactory] cache provider: net.sf.ehcache.hibernate.Provider
21:13:16,112 INFO [Configuration] instantiating and configuring caches
21:13:16,112 INFO [SessionFactoryImpl] building session factory
21:13:16,237 INFO [SessionFactoryObjectFactory] no JNDI name configured
21:13:16,238 INFO [STDOUT] This is the family being added to the DB: [Family] ID = null
P1 Title = Mr
P1 Last Name = Test
P1 First Name = Tom
P1 Home Phone = 1111111111
P1 Work Phone = 2222222222

21:13:16,244 INFO [STDOUT] Hibernate: select nextval ('tblfamily_id_family_seq')
21:13:16,258 INFO [STDOUT] Hibernate: insert into tblFamily (id_family) values (?)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 15, 2004 12:17 am 
Newbie

Joined: Sun Apr 11, 2004 12:13 pm
Posts: 7
you have insert="false" and update="false" on your property tags. This causes hibernate to not insert/update these properties. Get rid of them and all should be fine.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.