[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] pojo mapping
|
Map the Menu.owner to the ID column. You can then remove the id
attribute from Menu or map it as readonly. If you map it as readonly
you will have to ensure in your setOwner method to set the id attribute
to the id of Item or new instances will not have the id attribute
populated until refreshed from the database. If you do not want to add
this code to your setter or setting the ID value is not occurring as you
need because of when sequences are allocated you can also write a
postClone and postMerge event listener to ensure the value is placed in
the Menu.id.
if you would like more details feel free to ask.
Also is there a particular reason you have chosen to not use the Java
Persistence APIs?
--Gordon
WP Moore-Taylor wrote:
Can some one give me so help with this, I have 2 classes pojos mapped
to 2 tables using the workbench, item and menu.
Item uses a default sequencing and menus Id prim key needs to be the
same values as items. I know it can be done but can not getting it
working.
If some one could help that would be great.
in its simplest for they are like this
Tables
DROP TABLE IF EXISTS `test`.`item`;
CREATE TABLE `test`.`item` (
`ID` int(11) NOT NULL auto_increment,
`TEXT` varchar(20) default NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `test`.`menu`;
CREATE TABLE `test`.`menu` (
`ID` int(11) NOT NULL,
`TEXT` varchar(20) default NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
both just a ID and text.
the class are
import org.eclipse.persistence.indirection.ValueHolder;
import org.eclipse.persistence.indirection.ValueHolderInterface;
public class Item {
public Item() {
// TODO Auto-generated constructor stub
}
private ValueHolderInterface menu = new ValueHolder();
public Menu getMenu() {
return (Menu)menu.getValue();
}
public void setMenu(Menu menu) {
this.menu.setValue(menu);
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
private int id;
private String text="";
}
import org.eclipse.persistence.indirection.ValueHolder;
import org.eclipse.persistence.indirection.ValueHolderInterface;
public class Menu {
public Menu() {
// TODO Auto-generated constructor stub
}
public Menu(Item item) {
this.setOwner(item);
// TODO Auto-generated constructor stub
}
private ValueHolderInterface owner = new ValueHolder();
private int id;
private String text = "";
public Item getOwner() {
return (Item) owner.getValue();
}
public void setOwner(Item owner) {
this.owner.setValue(owner);
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users