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: Creates work but updates and deletes don't on any table
PostPosted: Sat Aug 13, 2005 11:50 am 
Newbie

Joined: Sat Aug 13, 2005 11:35 am
Posts: 5
Hibernate version:3


I have a simple test case that creates a row, updates another and deletes another. The create works find but the amendment to the second row and the delete don't get to the database.

Session session = HibernateUtil.currentSession();
Transaction transaction = session.beginTransaction();

Person person2 = (Person) session.get(Person.class, "grape");
person2.setName("pip");

Person person3 = (Person) session.get(Person.class, "peach");
session.delete(person3);

session.merge(person);
session.merge(person2);

transaction.commit();
setPerson(person);


I see a comment in the logs saying that it is ignoring the persisten instance: -

[org.hibernate.engine.PersistenceContext] initializing non-lazy collections
[org.hibernate.loader.Loader] done entity load
[org.hibernate.event.def.DefaultDeleteEventListener] deleting a persistent instance
[org.hibernate.event.def.DefaultDeleteEventListener] deleting [com.abc.def.model.Person#banana]
[org.hibernate.impl.SessionImpl] setting cache mode to: GET
[org.hibernate.impl.SessionImpl] setting cache mode to: NORMAL
[org.hibernate.impl.SessionImpl] setting cache mode to: GET
[org.hibernate.impl.SessionImpl] setting cache mode to: NORMAL
[org.hibernate.event.def.AbstractSaveEventListener] persistent instance of: com.abc.def.Person
[org.hibernate.event.def.DefaultMergeEventListener] ignoring persistent instance
[org.hibernate.event.def.AbstractSaveEventListener] persistent instance of: com.abc.def.model.Person
[org.hibernate.event.def.DefaultMergeEventListener] ignoring persistent instance
[org.hibernate.transaction.JDBCTransaction] commit

It looks like

Mapping is: -

<hibernate-mapping>
<class name="com.drkw.scd.model.Person" table="Person">
<id name="Id" access="field" >
<generator class="assigned" />
</id>
<property name="name" access="field" />
</class>
</hibernate-mapping>

It looks like Hibernate is not detecting calls to setters as changing the objects?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 13, 2005 1:09 pm 
Senior
Senior

Joined: Wed Jul 13, 2005 4:31 pm
Posts: 142
Location: Seattle, WA
I can see 2 problems -

Merge is used for -
Quote:
Copy the state of the given object onto the persistent object with the same identifier. If there is no persistent instance currently associated with the session, it will be loaded. Return the persistent instance. If the given instance is unsaved, save a copy of and return it as a newly persistent instance. The given instance does not become associated with the session.


Try replacing session.merge(person2) with session.update(person2)

Also, the instance being ignored is of type - com.abc.def.model.Person , but the mapped one is of type - com.drkw.scd.model.Person. The package names and hence the classes are different.

Perhaps you can post your imports as well.
Are you getting any exceptions?


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.