有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

保存集合时发生java Hibernate映射异常

Hi I am new to Hibernate and I am getting the following exception while trying to save a collection.

Could not determine type for: java.util.List, for columns

**Here are my codes**

    @Entity
    @Table(name="USER_DETAILS")

    public class User {

        @Id
        @GeneratedValue(strategy=GenerationType.AUTO)
        private int id;
        @ElementCollection
        private List<Address> aList=new ArrayList<Address>();


        @Embeddable

        public class Address {

        @Column(length=50)
        private String city;

        @Column(length=50)
        private String state;

        @Column(length=50)
        private String country;

        @Column(length=10)
        private int zip;
}

@Embeddable
public class Address implements Serializable{

    private static final long serialVersionUID = 1L;

    @Column(length=50)
    private String city;

    @Column(length=50)
    private String state;

    @Column(length=50)
    private String country;

    @Column(length=10)
    private int zip;

    public String getCity() {
        return city;
    }

        public class TestUser {

        public static void main(String[] args) {
            User user=new User();
            Address addr=new Address();

            addr.setCity("Asjasjs");
            addr.setCountry("gfgf");
            addr.setState("atyty");
            addr.setZip(345343);

            user.getaList().add(addr);

            Session session=SessionFactoryUtil.getSession();
            session.beginTransaction();

            session.save(user);

            session.getTransaction().commit();
            session.close();

        }

这就是它在数据库中存储数据的方式 enter image description here


共 (0) 个答案