Hibernate Issues

Anthony Berglas <[email protected]>
Newsgroups gmane.comp.java.orm.simpleorm
Message-ID <[email protected]>
I have been playing with Hibernate recently, and found more problems 
than I expected!

Given
@Entity
public class Event {
     @Id @GeneratedValue
      Long id;
      @Column
      String title;
      @OneToMany(mappedBy="event", fetch=FetchType.LAZY) // Lazy 
reccommened pp JPWH p570
      Set<Activity> activities = new HashSet();
      public Event getThis() {return this;}
}

and

@Entity
public class Activity {
     @Id @GeneratedValue
     long id;
     @ManyToOne(fetch=FetchType.LAZY)
     Event event;
     @Column
     String name;
}

Then
      Event event2bPre = (Event)session.get(Event.class, 2L);
      Activity act4bPre = (Activity)session.get(Activity.class, 4L);
      assertEqual("Second Event", act4bPre.event.title);
Works.

But
      Activity act4b = (Activity)session.get(Activity.class, 4L);
      assertTrue(act4b.event.getClass().getName().contains("Event$$EnhancerByCGLIB")); 
// Ahh!
      Event event2aPost = (Event)session.get(Event.class, 2L);
      assertTrue(null == act4b.event.title);
Does not work -- act4b.event.title should not be null.

I think that the weird proxy class is to blame.  I have sometimes 
even got Entity.getThis() != this(!).

The definitions for the classes are as recommended by the book, 
AFAIK.  I suspect that the annotations are not properly 
supported/documented, and have weird JPA issues, and so I would 
probably be better off sticking to XML.  (Have not tried.)

But I have spent several hours on this trivial example.

Needless complexity is evil.

Anthony



Dr Anthony Berglas, [email protected]       Mobile: +61 4 4838 8874
Just because it is possible to push twigs along the ground with ones nose
does not necessarily mean that is the best way to collect firewood.


------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/SimpleORM/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/SimpleORM/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[email protected] 
    mailto:[email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.