[Hibernate] How to delete orphan children

2004-09-17 Thread Michael Mehrle
I've got a list of child objects (keywords) that I'd like to store in a
separate table. My configuration is as such (it's xdoclet, but I'm sure you
can see the gist of it):

/**
* Returns the keyword list associated with the referenced physical asset.
*
* @hibernate.set table="ImageMaster_Keywords" lazy="false"
cascade="all-delete-orphan"
* @hibernate.collection-key column="imagemaster_fk"
* @hibernate.collection-one-to-many
class="com.enetworks.style2.ssms.common.dao.Keyword"
* @return List of keywords
*/
public Set getKeywords() {
return keywords;
}

I've used all-delete-orphan for the cascade definition since I want all
actions to be cascaded from the parent to the child, and in particular I'd
like orphan children to be deleted.

Well, it's not happening - one of my tests creates the parent object, sets a
bunch of keywords, then saves the object in the database. Then it retrieves
the same object and removes some of the keywords and stores it again. Now,
the old keywords that were removed are still in the database - the PK is set
to null, which makes sense, but that's behavior I would expect with all or
save-update and not with all-delete-orphan. Does anyone know what I need to
do to make this work?



---
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
___
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel


[Hibernate] Re: [appfuse-user] Resolved: Problems mapping List with Hibernate xdoclet tag

2004-09-14 Thread Michael Mehrle



Actually it didn't - after adding 
'java.lang.String' as the composite-element I get the following 
error:
 
C:\eonline\projects\style2.0\ssms-common\build.xml:418: Schema text 
failed: Association references unmapped class: java.lang.String

  - Original Message ----- 
  From: 
  Michael 
  Mehrle 
  To: Virender Dogra 
  Cc: [EMAIL PROTECTED] ; [EMAIL PROTECTED] 
  ; [EMAIL PROTECTED] 
  Sent: Tuesday, September 14, 2004 3:39 
  PM
  Subject: [appfuse-user] Resolved: 
  Problems mapping List with Hibernate xdoclet tag
  
  This actually worked!!! Virender - you are the 
  man! :-)
   
  I was banging my head against the wall with this 
  for days, and was about to give up.
   
  Thanks for helping out.
   
  Michael
  
- Original Message - 
From: 
Virender 
Dogra 
    To: Michael Mehrle 
Sent: Friday, September 10, 2004 12:47 
PM
Subject: RE: [Hibernate] Problems 
mapping List with Hibernate xdoclet tag

Try something like the following to complete the DTD 
requirements.
 
 /** Returns the keyword list associated with the 
referenced physical asset.   * @hibernate.list 
table="ImageMasterKeywords" lazy="false" 
cascade="save-update"
   *   * 
@hibernate.collection-key    
*    
column="KEYWORD_ID"   * 
@hibernate.collection-index    
*    
column="KEYWORD_ORDER"   * 
@hibernate.collection-composite-element    
*    
class="com.images.Keyword"    *  
 * @return List the keyworld list field.   
*/
- Virender


From: 
[EMAIL PROTECTED] 
[mailto:[EMAIL PROTECTED] On Behalf Of 
Michael MehrleSent: Friday, September 10, 2004 1:42 
PMTo: [EMAIL PROTECTED]Subject: 
[Hibernate] Problems mapping List with Hibernate xdoclet 
tag

This is what I'm doing:
 
 /** Returns the 
keyword list associated with the referenced physical asset.  * 
@hibernate.list table="ImageMasterKeywords" lazy="false" 
cascade="save-update"  *  * @return List the keyworld list 
field.  */ public List getKeywords() 
{  return keywords; }
 
And the error I get is this:
 
[hibernatedoclet] 
org.xml.sax.SAXParseException: The content of element type "list" is 
incomplete, it must mach 
"(meta*,(cache|jcs-cache)?,key,index,(element|one-to-many|many-to-many|composite-element|many-to-any))".[hibernatedoclet]   
at 
org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown 
Source)[hibernatedoclet]   at 
org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown 
Source)[hibernatedoclet]   at 
org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown 
Source)[hibernatedoclet]   at 
org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown 
Source)[hibernatedoclet]   at 
org.apache.xerces.impl.dtd.XMLDTDValidator.handleEndElement(Unknown 
Source)[hibernatedoclet]   at 
org.apache.xerces.impl.dtd.XMLDTDValidator.endElement(Unknown 
Source)[hibernatedoclet]   at 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown 
Source)
 
I tried to all types of variations, but nothing 
works. What is the correct way to store a simple List with Strings in a 
separate table?
 
Thanks!
 
Michael
 


[Hibernate] Resolved: Problems mapping List with Hibernate xdoclet tag

2004-09-14 Thread Michael Mehrle



This actually worked!!! Virender - you are the man! 
:-)
 
I was banging my head against the wall with this 
for days, and was about to give up.
 
Thanks for helping out.
 
Michael

  - Original Message - 
  From: 
  Virender 
  Dogra 
  To: Michael Mehrle 
  Sent: Friday, September 10, 2004 12:47 
  PM
  Subject: RE: [Hibernate] Problems mapping 
  List with Hibernate xdoclet tag
  
  Try something like the following to complete the DTD 
  requirements.
   
   /** Returns the keyword list associated with the 
  referenced physical asset.   * @hibernate.list 
  table="ImageMasterKeywords" lazy="false" 
  cascade="save-update"
     *   * 
  @hibernate.collection-key    
  *    
  column="KEYWORD_ID"   * 
  @hibernate.collection-index    
  *    
  column="KEYWORD_ORDER"   * 
  @hibernate.collection-composite-element    
  *    
  class="com.images.Keyword"    *   * 
  @return List the keyworld list field.   
  */
  - Virender
  
  
  From: 
  [EMAIL PROTECTED] 
  [mailto:[EMAIL PROTECTED] On Behalf Of 
  Michael MehrleSent: Friday, September 10, 2004 1:42 
  PMTo: [EMAIL PROTECTED]Subject: 
  [Hibernate] Problems mapping List with Hibernate xdoclet 
  tag
  
  This is what I'm doing:
   
   /** Returns the keyword 
  list associated with the referenced physical asset.  * 
  @hibernate.list table="ImageMasterKeywords" lazy="false" 
  cascade="save-update"  *  * @return List the keyworld list 
  field.  */ public List getKeywords() 
  {  return keywords; }
   
  And the error I get is this:
   
  [hibernatedoclet] 
  org.xml.sax.SAXParseException: The content of element type "list" is 
  incomplete, it must mach 
  "(meta*,(cache|jcs-cache)?,key,index,(element|one-to-many|many-to-many|composite-element|many-to-any))".[hibernatedoclet]   
  at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown 
  Source)[hibernatedoclet]   at 
  org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown 
  Source)[hibernatedoclet]   at 
  org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown 
  Source)[hibernatedoclet]   at 
  org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown 
  Source)[hibernatedoclet]   at 
  org.apache.xerces.impl.dtd.XMLDTDValidator.handleEndElement(Unknown 
  Source)[hibernatedoclet]   at 
  org.apache.xerces.impl.dtd.XMLDTDValidator.endElement(Unknown 
  Source)[hibernatedoclet]   at 
  org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown 
  Source)
   
  I tried to all types of variations, but nothing 
  works. What is the correct way to store a simple List with Strings in a 
  separate table?
   
  Thanks!
   
  Michael
   


Re: [Hibernate] Fetch strategy changes

2004-09-13 Thread Michael Mehrle
I did - and nobody is replying! Can someone just answer my question?

- Original Message - 
From: "Emmanuel Bernard" <[EMAIL PROTECTED]>
To: "Gavin King" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Sunday, September 12, 2004 11:44 PM
Subject: Re: [Hibernate] Fetch strategy changes


>
>
> Gavin King wrote:
>
> > In my private chats with people, it seems we all agree that
> > currently, Hibernate2 association fetch strategy configuration
> > is confusing and has nonsensible defaults. I've spent quite a
> > lot of time thinking about how we could clean this up without
> > breaking 2.x mapping documents too much, and come to the
> > conclusion that this would be the best approach:
> >
> > (1) make lazy default to true on both  and 
> >mapping elements; if a class cannot be proxied, laziness
> >is transparently disabled; make it clear that we intend
> >laziness to be used 99% of the time
>
> Most controversial part but I'm +1 from a pragmatic perspective.
> However, I can understand people thinking it's a bit too much since it's
> not 100% sure you can lazy, and the '1 query to bind them all' is a very
> common urban legend.
> We should emphasize *a lot* the fetch HQL keyword (complex to understand
> with its 1 collection fetched only). It'll be (if not already) a key tool.
>
> >
> > (2) provide , to
> >override this new default for backward compatibility
> >purposes
>
> +1
>
> >
> > (3) deprecate (remove?) the confusingly named outer-join
> >attribute
>
> +1, my favorite
>
> >
> > (4) introduce the fetch attribute, where, at least initially,
> >the options are fetch="join|select"; eventually we may
> >add other options like fetch="immediate-select"
>
> +1 immediate-select means unlazy but wo join, correct ?
>
> >
> > Questions:
> >
> > * The default should be fetch="select" for collections, what
> >  should the default be for to-one associations? I suppose
> >  that purely for backward compatibility purposes we need
> >  fetch="auto|join|select", where auto is the default, and
> >  chooses "select" for a lazy-enabled class.
>
> To stay consistent with (4), add a default value (I know one more). I've
> never been fond of the 'auto'-magical configuration. It has confused
> tons of guys I've worked with.
>
> >
> > * Should we provide XSLT stylesheets to transform 2.x mapping
> >  to 3.0 mappings, rather than providing backward compatibility
> >  at the mapping document level, by adding default-lazy and
> >  continuing to support the outer-join attribute?
>
> -0, some guys had the old style in mind, and they might want to keep it.
> The tool convertor is a one shot, not an every day choice.
>
> >
> > * Anything else needed?
>
> We *must* provide a clear and clean material on what to do to lazy,
> fetch a collection a to-one etc... We'll need a clean separation between
> H2 and H3 docs (whether wiki or not).
>
> >
> > * Does this suck?
>
> Nope, be ready to argue kindly with a lot of guys :-)
>
> -- 
> Emmanuel Bernard
> [EMAIL PROTECTED]
> http://www.hibernate.org
>
>
>
> ---
> This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
> Project Admins to receive an Apple iPod Mini FREE for your judgement on
> who ports your project to Linux PPC the best. Sponsored by IBM.
> Deadline: Sept. 13. Go here: http://sf.net/ppc_contest.php
> ___
> hibernate-devel mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/hibernate-devel
>
>



---
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM. 
Deadline: Sept. 13. Go here: http://sf.net/ppc_contest.php
___
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel


[Hibernate] Problems mapping List with Hibernate xdoclet tag

2004-09-10 Thread Michael Mehrle



This is what I'm doing:
 
 /** Returns the keyword 
list associated with the referenced physical asset.  * @hibernate.list 
table="ImageMasterKeywords" lazy="false" cascade="save-update"  
*  * @return List the keyworld list field.  
*/ public List getKeywords() {  return 
keywords; }
 
And the error I get is this:
 
[hibernatedoclet] 
org.xml.sax.SAXParseException: The content of element type "list" is incomplete, 
it must mach 
"(meta*,(cache|jcs-cache)?,key,index,(element|one-to-many|many-to-many|composite-element|many-to-any))".[hibernatedoclet]   
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown 
Source)[hibernatedoclet]   at 
org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown 
Source)[hibernatedoclet]   at 
org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown 
Source)[hibernatedoclet]   at 
org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown 
Source)[hibernatedoclet]   at 
org.apache.xerces.impl.dtd.XMLDTDValidator.handleEndElement(Unknown 
Source)[hibernatedoclet]   at 
org.apache.xerces.impl.dtd.XMLDTDValidator.endElement(Unknown 
Source)[hibernatedoclet]   at 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown 
Source)
 
I tried to all types of variations, but nothing 
works. What is the correct way to store a simple List with Strings in a separate 
table?
 
Thanks!
 
Michael
 


[Hibernate] Hibernate 'assigned' key problem

2004-09-03 Thread Michael Mehrle




You guys might remember the 'assigned' PK issue 
which I resolved by putting the following xdoclet into the javadoc of my ID 
field:
 
 /** Gets the guid.  *   * 
@return Returns the guid.  * @hibernate.id column="guid" 
generator-class="assigned" unsaved-value="null"  */ public 
String getGuid() {  return guid; }
 
Now, another issue I discovered was that 
saveOrUpdate didn't work and the solution was to specifically call save() or 
update() and that I had to manage the uniqueness of my assigned primary key 
myself. So far so good
 
The problem I have is that update() NEVER works. I 
always get a 'unique id integrity problem' (or something like it) when trying to 
update my entry. I wrote some code that checks if an entry of the given ID 
existed and if so, calls the update method (and save otherwise), but I still get 
that error. Another attempt of deleting the object and then storing it resulted 
in the old faithful: "a different object with the same identifier value was 
already associated with the session:" - something other people already had 
some fun with in the past.
 
Fact is that I cannot have my client code perform 
the checking/deleting of existing entries. I need them to be able to just call 
save(String id). What are my options at this point? I know that switching 
the PK to 'auto-generated' would alleviate all these problems, but the group is 
pretty insistend on sticking with the current schema.
 
Any input on this [before the long weekend] would 
be very much appreciated.
 
Enjoy your Labor Day weekend!
 
Michael