I am using aspectJ to insert the hibernate database accessing, and generate the mapping automatic with reflection.
Code:
Address adr = new Address( "1To1Address",
"1",
new Integer(60599),
"Frankfurt",
"Germany");
before the initialization the mapping will be generated, after the initialization it will be inserted in the database automatic with the following aspect.
Code:
try {
if ( session == null ){ buildNewSession(); }
tx = session.beginTransaction();
if (action.equalsIgnoreCase("save")) {
session.save(o);
} else if (action.equalsIgnoreCase("update")) {
session.update(o);
} else if (action.equalsIgnoreCase("delete")) {
session.delete(o);
}
tx.commit();
} catch (Exception e) {
if (tx != null)
tx.rollback();
e.printStackTrace();
}
if i use one-to-one primary association , during the initialization i do not know the person id, and i must insert the address in the database. so i think i use the many-to-one relation, and after adr.setPerson(p), save with session.update(adr) the person_id. but the update do not add the person_id to the address table.