javaclassinstantiationembeddable

How to instantiate an Embeddable class?


I have a class which has an embeddable class:

public class User {
  ....
@Embeddable 
public static class UserPK{

@Column (name="idUser")
private Long idUser;

 @Column (name="idSubject")
private Long idSubject;

} 
@EmbeddedId
private UserPK userPK;


}

I need to instantiate "UserPK" but it's not working. Help Please!

I've tried to instantiate it as an inner class, as a single class.. it compiles but it doesn't creates the object.


Solution

  • I was right about the import..

    When i was trying to do:

    User.UserPK userpk = new User.UserPK();

    It was failing because i had an import like this one:

    org.company.User.UserPK;

    What I did to solve it it's let the import like this:

    org.company.User;

    It allowed me to instantiate the class as an inner one.

    Thanks for those who helped me.