-->
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.  [ 3 posts ] 
Author Message
 Post subject: one-to-one relation
PostPosted: Mon Oct 04, 2010 7:39 am 
Regular
Regular

Joined: Wed Mar 10, 2010 4:48 am
Posts: 106
I'm having problems with an one-to-one relation.

The error is:
Code:
ERROR - (BasicPropertyAccessor.java:118) - IllegalArgumentException in class: data.Employee, setter method of property: storeOwner
ERROR - (BasicPropertyAccessor.java:122) - expected type: data.StoreOwner, actual value: java.lang.Boolean
ERROR - (CustomersPanel.java:586) - IllegalArgumentException occurred while calling setter of data.Employee.storeOwner
This doesn't says the problem is the one-to-one relation, but I started getting this error when I changed a many-to-one to an one-to-one relation.

I have 2 objects StoreOwner and Employee. Each StoreOwner is an Employee, an Employee doesn't has to be a StoreOwner.

Below are the mappings and classes:
Code:
    <class name="data.StoreOwner" table="storeOwners">
        <id name="id" column="id" length="31">
            <generator class="assigned" />
        </id>

        <many-to-one name="employee" class="data.Employee" column="employee" unique="true" />
    </class>

    <class name="data.Employee" table="employees">
        <id name="id" column="id" length="31">
            <generator class="assigned" />
        </id>

        <one-to-one name="storeOwner" class="data.StoreOwner" property-ref="employee" />
    </class>
Code:
public class StoreOwner extends Data
{
    private Employee employee;

    public StoreOwner()
    {
       
    }

    public Employee getEmployee()
    {
        return employee;
    }

    public void setEmployee(Employee employee)
    {
        this.employee = employee;
    }
}

public class Employee extends Data
{
    private StoreOwner storeOwner;

    public Employee()
    {
       
    }
   
    public StoreOwner getStoreOwner()
    {
        return storeOwner;
    }
   
    public void setStoreOwner(StoreOwner storeOwner)
    {
        this.storeOwner = storeOwner;
    }
}
The problem occurs when I save a new Employee.
I've got this from 5.1.13. One-to-one and I've never used an one-to-one relation in Hibernate before.

Does anyone has an idea? Am I missing an attribute in the mapping?


Top
 Profile  
 
 Post subject: Re: one-to-one relation
PostPosted: Mon Oct 04, 2010 8:10 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Do you have an isStoreOwner() method (returning a boolean) in the Employee class? If so, it may interfere with the way Hibernate detects setters/getters and their parameter types.


Top
 Profile  
 
 Post subject: Re: one-to-one relation
PostPosted: Mon Oct 04, 2010 8:18 am 
Regular
Regular

Joined: Wed Mar 10, 2010 4:48 am
Posts: 106
Thanks a lot. I renamed the method isStoreOwner() and that solved it.


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