-5

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.

  • 2
    `Embeddable` has nothing to do with your problem. – Andremoniy Apr 09 '15 at 08:24
  • 2
    Are you able to understand that we can't help on a problem that is described by a simple "but it's not working"? – Seelenvirtuose Apr 09 '15 at 08:28
  • I believe those threads might help you : http://stackoverflow.com/questions/12836506/why-instantiation-of-static-nested-class-object-is-allowed , http://stackoverflow.com/questions/70324/java-inner-class-and-static-nested-class and http://stackoverflow.com/questions/18293857/can-a-static-nested-class-be-instantiated-in-java – flafoux Apr 09 '15 at 08:29
  • It's not working means: I've tried to instantiate it.. it compiled..and debugging i've looked for the object and i can't find it anywhere.. So i Thought maybe the problem is the embeddable.. – DeveloperCat Apr 09 '15 at 08:31
  • 1
    Please show the code that reveals the problem (the code that is using your class). – Dirk Lachowski Apr 09 '15 at 08:44
  • The code it's easy, It's just a mapped class.. I'm trying to create an object of UserPK. I've tried to instantiate is as an inner class but compiler fails... I don't have a clue about it.. – DeveloperCat Apr 09 '15 at 08:58
  • What we're trying to say is, post the error. – Evan Knowles Apr 09 '15 at 09:04
  • There is no error! Because the error which shows is produced because the object which i'm trying to create is not created.. So i Instantiate the object.. and it's like the lines i've developed are not written.. Now I've discovered i had an import "org.company.User.UserPK" so i've deleted the "UserPK" part and now, allows me to instantiate as an inner.. but again.. it's like i haven't wrote anything. – DeveloperCat Apr 09 '15 at 09:14
  • You have declared `private UserPK userPK;` but you have not instantiated it. – articuno Apr 09 '15 at 09:21
  • And the code where you instantiate it? – Evan Knowles Apr 09 '15 at 09:22
  • I tried to instantiate in another class "UserServiceImpl".. But i don't think that's the problem.. – DeveloperCat Apr 09 '15 at 09:44

1 Answers1

0

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.