Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] OneToOne always results in two selects

Hello Tom,

Thank you!

Do I also need to enable weaving when I run my application in a JEE application server like glassfish?

regards,
Leon




On Nov 3, 2011, at 1:38 PM, Tom Ware wrote:

> The most likely reason you see two selects is that in order to get LAZY loading to work, you need to enable weaving.
> 
> http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_%28ELUG%29#Using_EclipseLink_JPA_Weaving
> 
> 
> On 03/11/2011 8:34 AM, Leon Derks wrote:
>> Hello
>> 
>> I have a problem with my OneToOne relationship., which always results in two
>> selects.
>> 
>> This is my query: select up from UserProfile up where up.profileCode = :profileCode
>> 
>> 
>> This is my (simplified) UserProfile Class:
>> 
>> public class UserProfile extends BaseEntity {
>> 
>> @Column(name = "PROFILE_CODE", nullable = false, unique=true)
>> privateString profileCode;
>> 
>> @OneToOne(fetch=FetchType.LAZY, optional=false)
>> @JoinColumn(name="USER_ID", unique=true, nullable=false)
>> private User user = new User();
>> }
>> 
>> These are the SQL Queries:
>> 
>> SELECT ID, PROFILE_CODE, USER_ID FROM USER_PROFILES WHERE (PROFILE_CODE = ?)
>> SELECT ID, EMAIL, GENDER, INITIALS, LAST_NAME, PHONE_NUMBER, SIGNUP_DATE, CITY,
>> HOUSE_NUMBER, POSTCODE, STREET FROM USERS WHERE (ID = ?)
>> 
>> No matter what I do (FetchType.Lazy, optional=false etc), Eclipselink always
>> generates 2 selects.
>> What I want is just one select for the UserProfile with the profileCode!
>> 
>> Can somebody explain to me why there is always an additional select for the user
>> object?
>> 
>> Thank you!
>> Leon
>> 
>> 
>> 
>> _______________________________________________
>> eclipselink-users mailing list
>> eclipselink-users@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users



Back to the top