-->
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.  [ 6 posts ] 
Author Message
 Post subject: Update happening before Insert
PostPosted: Tue Jun 22, 2004 9:26 pm 
Newbie

Joined: Tue Jun 08, 2004 8:07 pm
Posts: 14
Location: Washington, D.C.
I have the folllowing mapping file hacked up....

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="AclImpl" table="control_lists">
<id name="name" type="string" column="acl_key">
<generator class="assigned"/>
</id>
<many-to-one name="owner" class="PrincipalImpl" access="field" column="principal_key" cascade="all" />
<map name="individualToPositivePermission" cascade="all">
<key column="acl_key" />
<index-many-to-many class="PrincipalImpl" />
<many-to-many class="AclEntryImpl"/>
</map>
</class>
</hibernate-mapping>

And I see this output upon saving the AclImpl...

21:20:20,152 DEBUG SQL:237 - insert into control_lists (principal_key, acl_key) values (?, ?)
21:20:20,162 DEBUG SQL:237 - update acl_entries set negativePermission=? where acl_entry_key=?

This fails because the AclEntryImpl hasn't been saved to the database yet. Anything obvious I'm missing here?

looking forward to Hibernate In Action hitting book stores! ...

~harris


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 2:55 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
show java code

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject: same question. waiting......
PostPosted: Wed Jun 23, 2004 3:52 am 
Newbie

Joined: Mon Jun 21, 2004 9:56 pm
Posts: 4
I had same problem as you.

http://forum.hibernate.org/viewtopic.php?t=931958

the difference is I'm not using one-to-many relationship,
the result is same (with the transaction management)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 4:24 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
hi guys,
please read again parent/child relationship,
also check "inverse" doc on the wiki

and if after that, you don't understand, come back here, in this post

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 4:56 am 
Newbie

Joined: Mon Jun 21, 2004 9:56 pm
Posts: 4
but did you see my post?
I haven't any relationship,
and my code is update first,then update ,
but the output is insert and update.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 10:38 am 
Newbie

Joined: Tue Jun 08, 2004 8:07 pm
Posts: 14
Location: Washington, D.C.
Here's the jave code...

Acl accessList = AclFactory.getAcl( owner, "exampleAcl" );

Principal testUser = PrincipalImpl( "testUser" );
Permission fileRead = PermissionImpl( "readFile" );

AclEntry negativeEntry = AclFactory.getAclEntry( testUser );
negativeEntry.addPermission( fileRead );
accessList.addEntry( owner, negativeEntry );

SessionFactory factory = HibernateUtil.getSecuritySessionFactory();
Session session = factory.openSession();
Transaction transaction = session.beginTransaction();
session.save( accessList, accessList.getName() );
transaction.commit();

... Acl class has a map of Principal -> AclEntry. I would like to just save the accessList and have Hibernate automatically handle the map underneath by saving the Principals and associated AclEntry.

From re-reading the Parent-Child doc though this doesn't seem possible. There, it appears necessary to manually save Child references.

Also, another problem, is that the AclEntry (child) does not know anything about the Acl (parent), which is different from the Parent/Child example.

It seems like saving maps with complex types for keys and values is one of the more complicated things to do. Is is possible to just save a parent class and have the map it contains to be saved automatically?

thanks,

~harris


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