-->
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.  [ 5 posts ] 
Author Message
 Post subject: Annotations 3.0 alpha X problems with OneToOne properties...
PostPosted: Wed Jan 26, 2005 7:39 am 
Newbie

Joined: Tue Jan 25, 2005 12:25 pm
Posts: 9
I am using Annotations 3.0 alpha 2 + Hibernate 3.0 beta2. I have an Account class with a property like this:

@OneToOne(cascade=CascadeType.ALL)
@JoinColumn(name="role_id", unique=false, nullable=false)
public Role getRole() {
return role;
}

And the Role class like this:

@Id(generate=GeneratorType.AUTO)
public Long getId() {
return id;
}

and so on...
I got this when accessing the Role methods after loading a saved Account from the database and closing the session:

org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed

I thought the lazy was disabled by default on OneToOne, and looking at the Account loading logs, i see that it's not true:

DEBUG [main] resolving associations for [it.airventsam.markab.core.security.Account#294913]

DEBUG [main] loading entity: [it.airventsam.markab.core.security.Role#327681]

DEBUG [main] creating new proxy for entity

Why that? I dont want proxies because i need to access that data after session is closed. Can you help me?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 26, 2005 7:40 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Check the new section about fetching strategies in the reference documentation. Lazy/proxies is the default in Hibernate3.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 26, 2005 9:35 am 
Newbie

Joined: Tue Jan 25, 2005 12:25 pm
Posts: 9
I already checked that : it's not true. Reading the EJB3.0 specifications, the OneToOne default fetch method is EAGER and not LAZY. I already tried changing my code into:

@OneToOne(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
@JoinColumn(name="role_id", unique=false, nullable=false)
public Role getRole() {
return role;
}

But hibernate still use proxies for that property. This is a big problem because OneToOne annotation is very useful and not rarely used.

Any hint?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 26, 2005 9:43 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Submit a JIRA issue for Annotations.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 26, 2005 1:35 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Thank's I'll check that one

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.