How to load my object using sleep mode when there is double @id in my bean entity?

@Id
int master_id;

@Id
int id;

... this does not work:

User user= (User) session.load(User.class, new Integer(master_id), new Integer(id));

load(Class theClass, Serializable id) 

I replaced the last two arguments with a serializable object and still cannot extract the object.

+3
source share
1 answer

Well, the problem is solved using @Embeddable!

@Embeddable
public class UsertId implements Serializable{
    int master_id;
    int id;
    //.....setter &getter
}

//and in the bean, the type for Id should be UsertId
@Id
UsertId id;
+2
source

Source: https://habr.com/ru/post/1706043/


All Articles