Hello, sorry for my bad english.
I now have a new problem (the most strange is that I think I have exactly the same code in two different computers, but I have the error only on one of them.
So, I am just trying to understand the use of oneToMany and ManyToOne annotations.
My database schema is very simple:
Code:
CREATE TABLE PERSON(
ID INTEGER,
NAME VARCHAR(50) NOT NULL,
CONSTRAINT PK_PERSON PRIMARY KEY (ID)
);
CREATE TABLE ADDRESS(
ID INTEGER,
PERSON_ID INTEGER NOT NULL,
ADDRESS VARCHAR(100) NOT NULL,
CONSTRAINT PK_ADDRESS PRIMARY KEY (ID),
CONSTRAINT FK_PERSON FOREIGN KEY (PERSON_ID)
REFERENCES PERSON(ID)
ON DELETE CASCADE
ON UPDATE CASCADE
);
So I have a onetomany relation between Person and Address.
And the entities corresponding...
Person
Code:
@Entity
@Table(name="PERSON")
@NamedQueries({
@NamedQuery(name="person.findAll", query="SELECT p FROM Person p"),
@NamedQuery(name="person.findByName", query="SELECT p FROM Person p WHERE p.name LIKE :name")
})
public class Person implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
private String name;
private Collection<Address> addresses;
public Person(){}
public Person(String name){
this.name= name;
}
/********************************/
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
this.logger.info("<getId>");
return id;
}
public void setId(Long id) {
this.logger.info("<setId>");
this.id = id;
}
public String getName() {
this.logger.info("<getName>");
return name;
}
public void setName(String name) {
this.logger.info("<setName>");
this.name = name;
}
@OneToMany(mappedBy="person_id",cascade=CascadeType.ALL)
public Collection<Address> getAddresses() {
return this.addresses;
}
public void setAddresses(Collection<Address> addresses) {
this.addresses = addresses;
}
/**********************************/
...
}
Adress
Code:
@Entity
@Table(name="ADDRESS")
public class Address implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
private Long person_id;
private Person person;
private String address;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getPerson_id() {
return person_id;
}
public void setPerson_id(Long person_id) {
this.person_id = person_id;
}
@ManyToOne
@JoinColumn(name="person_id")
public Person getPerson() {
return person;
}
public void setPerson(Person person) {
this.person = person;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
...
}
And I have the following error (at deployment):
[code]
org.hibernate.MappingException: Repeated column in mapping for entity: app.ejb.entity.Address column: person_id (should be mapped with insert="false" update="false")
[code]
I absolutely don't understand...
Does someone can identify the problem in this example? Because for me it's impossible to do more easy.
Thanks in advance.