-->
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.  [ 4 posts ] 
Author Message
 Post subject: Problems with Setter - argument type mismatch on Many-to-one
PostPosted: Thu Dec 18, 2003 5:50 pm 
Newbie

Joined: Fri Dec 12, 2003 2:12 am
Posts: 16
I have two classes - AddressList and UserAccount. The AddressList class has a foreign-key to UserAccount. Technically, it's a one-to-one, but I've set it up as a many-to-one as per the docs, as it's a unique foreign-key - the address_list_id does not match the user_account_id in nearly all cases.

Here's the mapping:

<hibernate-mapping>
<class name="stresstest.hibernate.AddressList" table="address_list">
<id name="AddressListID" column="address_list_id" type="java.lang.Long">
<generator class="identity"/>
</id>
<many-to-one name="UserAccountID" class="stresstest.hibernate.UserAccount" column="user_account_id"/>
</class>
</hibernate-mapping>

<hibernate-mapping>
<class name="stresstest.hibernate.UserAccount" table="user_account">
<id name="ID" column="user_account_id" type="java.lang.Long">
<generator class="identity"/>
</id>
</class>
</hibernate-mapping>

And here's the getter/setter methods of the classes

public class AddressList
{
...
public void setUserAccountID(Long ua)
{
m_lUserAccountID = ua;
}
public Long getUserAccountID()
{
return m_lUserAccountID;
}
...
}

public class UserAccount
{
...
public void setID(Long id)
{
m_lUserAccountID = id;
}
public Long getID()
{
return m_lUserAccountID;
}

public void setUserAccountID(Long id)
{
setID(id);
}
public Long getUserAccountID()
{
return getID();
}
...
}

And here's the error:

Hibernate: select addresslis0_.address_list_id as address_1_1_, addresslis0_.user_account_id as user_acc2_1_, useraccoun1_.user_account_id as user_acc1_0_ from address_list addresslis0_ left outer join user_account useraccoun1_ on addresslis0_.user_account_id=useraccoun1_.user_account_id where addresslis0_.address_list_id=?

net.sf.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of stresstest.hibernate.AddressList.UserAccountID

If I remove the many-to-one mapping in AddressList and replace it with a <property.../>, the problem disappears. That is a bit confusing - the UserAccountID is still there, and still needs to be set; why an exception just because it's a many to one?

My initial inclination was that their was a disconnect in the parameter of the setter - long vs Long (or maybe int vs Long) but playing around, and making sure I was using type="java.lang.Long" didn't fix the problem.

It would be nice if Hibernate said what type of parameter it was trying to give to the setter.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 18, 2003 6:27 pm 
Regular
Regular

Joined: Fri Sep 05, 2003 12:01 am
Posts: 80
Location: Bogot
uhm... wheres you one-to-many?

I still dont understand why you want to use one-to-many ..

_________________
Mauricio Hern


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 18, 2003 6:36 pm 
Regular
Regular

Joined: Fri Sep 05, 2003 12:01 am
Posts: 80
Location: Bogot
oopss sorry... read wrong...

the many-to-one will give you an instance of UserAccount in your case.

try changing
Code:
public void setUserAccountID(Long ua)
{
m_lUserAccountID = ua;
}
public Long getUserAccountID()
{
return m_lUserAccountID;
}


to (change m_lUserAccountID from long to UserAccount)

Code:
public void setUserAccountID(stresstest.hibernate.UserAccount ua)
{
m_lUserAccountID = ua;
}
public stresstest.hibernate.UserAccount getUserAccountID()
{
return m_lUserAccountID;
}




hope it helps[/code]

_________________
Mauricio Hern


Top
 Profile  
 
 Post subject: Re: Problems with Setter - argument type mismatch on Many-to
PostPosted: Thu Dec 18, 2003 8:42 pm 
Newbie

Joined: Fri Dec 12, 2003 2:12 am
Posts: 16
Duh - thanks - that makes perfect sense.

Like I said, it would be a great debugging feature if Hibernate would tell you the type of object it was trying to set....

Thanks again.
David.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.