English 中文(简体)
Eclipselink 很多人与许多人的关系,没有导致加入圆桌会议。
原标题:Eclipselink many to many relationship, no result in join-table

I java ee项目有两个实体类别:Employee和Shft,它们之间有许多重复工作。 它希望:



    @Entity
    public class Employee implements Serializable {
    @ManyToMany(mappedBy="employees")
    private List shifts;
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String surname;
    private String firstname;


......



    @Entity

    public class Shift implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    private Date timeStart;
    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    private Date timeEnd;
    private int workers;
    private int overseers;
    @ManyToMany
    private List employees;

我有一个共同基金网页,希望把雇员(一个或一个)增到在我背后的传票上选择的班子:



    public void addToShift(Employee e){
            selectedShift.addEmployee(e);
            e.addShift(selectedShift);      
    }

After the method is called, i see nothing in the join table. I tried a few things, like looking up the entities again using entitymanager.find, but nothing really helped, i can t see anything in the join table and i can t see why. There were no problem managing employees and shift, it s "just" the connection...... Do you have any ideas?

最佳回答

Simply setting values to detached entities is not enough. You still have to call EntityManager.merge inside transaction. Then after when transaction is committed (or entitymanager is flushed) you will see results in database as well.

如果持续存在的情况仍然开放(在你看来不是这样),光靠流动是不够的,不需要合并。

问题回答

暂无回答




相关问题
Recommended way to develop using Jetty and Eclipse

I am currently developing a J2EE application and I would like to use Jetty. I would like to have iot integrated with Eclipse, so I could debug the appliaction. I ve tried out couple of plugins (...

Call function periodically in Java

we need run one function periodically in Java web application . How to call function of some class periodically ? Is there any way that call function when some event occured like high load in server ...

Why make an EJB rather than a Web Service?

I would have thought that there is a lot of information out there on this, but I haven t found anything that really answers my question. What are the advantages of making an EJB rather than a web ...

Where should I put this configuration setting?

I m designing a fairly small web application which will run on a Sun application server (v9.1). It only has a few pages, no database of its own, and will retrieve/update data via web services. There s ...

JNDI Names -- Is Prefix "jdbc/" needed?

What s up with JNDI names? I m trying to get a javax.sql.DataSource using the new annotations feature of Java 5. It s not working for me, so I want to ask... I have a in my web.xml, inside of it is ...

hibernate interceptors : afterTransactionCompletion

I wrote a Hibernate interceptor : public class MyInterceptor extends EmptyInterceptor { private boolean isCanal=false; public boolean onSave(Object entity, Serializable arg1, Object[] arg2, String[]...

热门标签