-->
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.  [ 3 posts ] 
Author Message
 Post subject: persist an object with reference to "static" table
PostPosted: Fri May 23, 2008 1:46 pm 
Newbie

Joined: Wed Mar 28, 2007 2:30 pm
Posts: 2
i have a schema that involves something like this:

Entity1 -> Mapping Table <- Static1

Entity1 is a "real data" table
Mapping1 is a mapping with a key to Entity1 and a key to Static1
Static1 is a "static lookup table" (aka metadata)

when i have hibernate generate the entities, Entity1 contains a Collection mapping that references the "static lookup table", which is fine for Fetches, but i when i persist a new Entity1, i do not want it to cascade the child objects because they already exist in the database (the static lookup table) and merely want it to persist the mapping entry ( Entity1-> id, Static1 -> id).

what i envision is, i create an Entity1, populate the collection (that represents the mapping) with dummy records with the Static1->id populated but leaving the other columns empty or null, and when i submit the Entity1 to persist(), it will render the mapping but not overwrite the Static1 entries with the dummy versions. is there a way to annotate this type of relationship (where the fetch is aware of the children, but the persist/merge only handle the key mapping)? OR do i have to write a custom persist/merge method(s) that decouple the persist/merge where i only need the linkages created and not cascade down to the children records?

== stanton


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 23, 2008 4:35 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
I think
Code:
@Cascade
could help, you just have to disable the relationship from "cascading" persist and update operations.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: simpler than i thought
PostPosted: Fri May 23, 2008 6:57 pm 
Newbie

Joined: Wed Mar 28, 2007 2:30 pm
Posts: 2
basically, after reflecting the schema, i went in and reverse engineered the references to the "static entities" and replaced them with their primitive types (String, Integer, BigInteger, etc.) and @labeled them as @Column rather than @JoinColumn.

this way, the keys are still assignable, and hibernate wont perform any "unwanted magic" when data comes in.

the downside is i will have to "explicitly" fetch the rows from these static tables when needed, but since they are primarily for export/reporting, i can facade them and gather them in bulk for efficiency.

== stanton


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