Hi,
I have the following problem:
I have two tables:
Logon
-username
-password
-company_id
Company
-Name
So Company has a OneToMany Relation to Logon and Logon a ManyToOne to company
I have created the following Entity classes:
class Logon{
...
@ManyToOne()
@JoinColumn(name = "COMPANY_ID",insertable=false, updatable=false)
private Company company;
...
}
class Company{
...
@OneToMany(mappedBy="company", cascade=CascadeType.ALL)
private Collection<Logon> logons = new Vector<Logon>();
}
And here is the code to insert the data.
Logon logon = new Logon();
Company company = new Company();
logon.setCompany(company);
company.addLogon(logon);
EntityTransaction trans = em.getTransaction();
trans.begin()
em.persist(logon);
em.persist(company);
trans.commit();
After that code I have an entry in table Logon and an entry in table Company.
But the field company_id in table logon is always set to 0 and not to the company's id.
The tables where not created from the entities. I have to work with an existing MySQL DB.
Does someone has an idea?
regards
Gerald