-->
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.  [ 1 post ] 
Author Message
 Post subject: One-to-one <-> Many-to-one problem with constrainted=&
PostPosted: Tue Mar 14, 2006 4:13 pm 
Newbie

Joined: Thu Jun 03, 2004 2:10 am
Posts: 19
Hibernate version: 3.1.2

I have a simple scenario which is giving me problems.

I have two mappings. A Company and a CompanyLogo. Right now, a company can only have one logo (this might change in the future), so here is my mappings:

<class name="Company" table="company">
<id name="companyId"
type="java.lang.Long"
column="company_id"
unsaved-value="0">
<generator class="native"/>
</id>

.... properties here ...

<one-to-one name="companyLogo"
class="CompanyLogo"
cascade="all"
constrained="true"
lazy="proxy"
property-ref="company">
</one-to-one>
</class>

<class name="CompanyLogo" table="company_logo" lazy="true">
<id name="companyLogoId"
type="java.lang.Long"
column="company_logo_id"
unsaved-value="0">
<generator class="native"/>
</id>

<many-to-one name="company"
class="Company"
column="company_id"
cascade="none"
not-null="true"
unique="true"
fetch="select"
index="idx_company_logo_company">
</many-to-one>
</class>

As you can see the CompanyLogo has it's own native primary key and has a many to one relationship with Company.

I tried the following code:

Company c = new Company();

... set properties ...

CompanyLogo l = new CompanyLogo();
l.setCompany(c);
c.setCompanyLogo(l);

... get session ...

ses.save(c);

This throws a null or transient exception on CompanyLogo.company...

If i change the company mapping from constrained="true" to constrained="false" it will work, but I want to keep it so that i have lazy support. In addition, a logo always exists for a company (just not always full of data).

Any have any ideas how I can get this working?

Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.