简体   繁体   中英

How to save a class in a entity class?

I have some trouble with creating an object in an entity class. I get following exception:

java.lang.IllegalArgumentException: A: name.A is not a supported property type

Here is a small code example:

This is my entity B class:

@Entity
public class B {        
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Key key;

    private ArrayList<A> token = new ArrayList<A>();

    public Profile() {
        this.token.add(new Token(1));
        this.token.add(new Token(2));
        this.token.add(new Token(3));
        this.token.add(new Token(4));
    }
}

This is my standard A class:

public class A {
    private Integer id = new Integer(0);

    public A(int id) {
        this.id = id;
    }
}

I save the class B in the datastore. I get the exception at following point:

profile = new Profile();
em.persist(profile);
em.close(); //Exception

If I comment the token object in class B everything is working. How could I use the class A in B?

I believe the issue is that class A is not being identified as an entity to be managed. Can you use the following annotation at the top of Class A and see.

@Embeddable
public class A

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM