-->
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.  [ 2 posts ] 
Author Message
 Post subject: many-to-one using a NOT NULL (that should be NULL)
PostPosted: Wed Jun 30, 2004 11:45 am 
Newbie

Joined: Fri Jan 16, 2004 9:32 am
Posts: 11
hello. two beans: person and company - a person may have 0 or 1 companies. in the database, person has a company_id field.

originally, the person.company_id field was null-able and everything was fine. recently, the client requested that we not store nulls in that field because it is causing problems in their other systems. they want an integer value of 0 to be stored instead. obviously this doesn't work - because there is no company with an id of 0.

my question is - is there a way to handle this in hibernate? (i'd love to leave the null constraint in, as removing it and using a magic number is...not desirable. but i'm looking for options.)

i appreciate your time.
chris

** exception thrown **
UnresolvableObjectException: No row with the given identifier exisits: 0, of class: CompanyBean

** many-to-one declaration inside person **
<many-to-one name="company" class="com.ci.db.member.CompanyBean" column="company_id"/>

** details
hibernate version: 1.2.5
db: mysql


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 02, 2004 12:05 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
A custom ClassPersister impl could deal with this. I good bet would be to start with the EntityPersister class as a base and overriding the various load(), update(), insert(), and delete() methods (and possibly even the instantiate() method).


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