-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi, I must show this question in hibarnate's forum, as the site is in maintenance for now, I put it here :)
Here is my code
Server.java
@Entity @Table(name = "server") public class Server { .... @OneToMany(mappedBy="server", fetch=FetchType.EAGER) @Column(name="id") protected Set<Site> sites; .... public void addSite(Site site) { site.setServer(this); this.getSites().add(site); } public void removeSite(Site site) { this.getSites().remove(site); }
Site.java
@Entity @Table(name = "site") public class Site { @ManyToOne @JoinColumn(name="server_id") protected Server server; }
For the test, we have 2 sites and 1 server in database
Site site1 = siteDAO.find(1); Site site2 = siteDAO.find(2); Server server1 = serverDAO.find(1); server1.addSite(site1); server1.addSite(site2); serverDAO.merge(server1);
But here, the merge didn't work, it didn't update database :(
Soneone have an idea, plzz help me
Thanks
P/S: all the configuration of Hibernate were done by Zeta Form Builder
You need to cascade "Updateaction" like this:
@OneToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE }, mappedBy = "planung"
However, map OneToMany (without eager) can produce overhead, i.e. list all servers load all sites!
I use this only for small database files. For larger files i map only @xxxtoOne and update with the DAO/Servicelayer from the detail.
Of course, sometimes a mapped detail could be very nice. i.e. if the user can free edit the details (like here (click anonym). The user could change details directly in the grid, but i only need a DAO/ServiceLayer.merge(head). Since i use (live) databinding, i do not need any extra action. Hibernate updates only changed rows -i love that.
/Robert
Asked: 2009-04-24 08:26:07 +0800
Seen: 284 times
Last updated: Apr 24 '09