Hi,
I'm working with Struts 2 and Hibernate 3for about two weeks and it's my first experience with both. I'm having difficulty with 1:n relations.
I've got two tables: Company and Person.
Company has an owner, which is a reference to a specific Person.
I've implemented the mapping like this in Company.hbm.xml:
Code:
<many-to-one column="OWNER_ID" name="owner" class="model.person.Person"/>
The Company class has a getter and setter:
Code:
private Long id;
public Long getId() {return id;}
public void setId(Long id) {this.id = id;}
The CompanyAction class used by Struts has:
Code:
private List persons;
private static PersonService personService = new PersonServiceHibernate();
public void prepare() throws Exception {
persons = personService.getAllPersons();
...
}
And the Company.jsp (which uses Struts 2) has:
Code:
<s:select label="%{getText('company.label.owner')}" name="company.owner" list="persons" listKey="id" listValue="firstName" emptyOption="true"/>
The JSP creates a nice choice-box (I would rather have an LOV pop-up with some search functionality, but that's for later). I can select the correct Person by name and the value is also present (checked in the html).
However, when I submit the form, I get the following error:
Code:
javax.servlet.ServletException: org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of model.person.Person.id
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:518)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:421)
root cause
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of model.person.Person.id
org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:171)
org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:183)
org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3585)
etc.
If I submit without filling in an owner, all works fine. I guess, when any one of my companies has an owner, the error occurs. Can anyone help me out?
Tnx in advance
Code: