So, I have a POJO with 

private String name;
@Column(length=256,nullable=false)
public String getString() { return name; }

But when I add:
private int count;
@Column(nullable=false)
public int getCount() { return count; }

Things seem to go haywire.

org.springframework.orm.hibernate3.HibernateSystemException: Null value was
assigned to a property of primitive type setter of com.talldean.Food.count

So I can have the class use Integer instead of int, but other than that, I'm
still stumped for using the primitive type.  The Hibernate FAQ gives me:

"A PropertyAccessException often occurs when the object being passed to the
setter method is of the wrong type. Check your type mappings for the
offending property. (To see exactly which property was the problem, you
might need to disable the CGLIB reflection optimizer.) However, the most
common cause of this problem is that Hibernate attempted to assign null to a
property of primitive type.

If your object has a primitive-type property mapped to a nullable database
column then you will need to use a Hibernate custom type to assign a
sensible default (primitive) value for the case of a null column value. A
better solution is usually to use a wrapper type for the Java property."

What they don't seem to say, and what 20 minutes of searching didn't find,
was how to assign a default primitive value for the case of a null column
value.  I've already tried changing the definition to: int count = 0;, and I
don't see an annotation to set a default value.  

Help?
-- 
View this message in context: 
http://www.nabble.com/Annotated-default-values-in-POJOs--tf3287676s2369.html#a9144904
Sent from the AppFuse - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to