這裏是我的實體類@ElementCollection:錯誤無法確定類型:java.util.Set中,爲列
@Entity // Model Class as a DB entity
public class UserDetails
{
@Id
private int userId;
private String name;
@ElementCollection
private Set<Address> listOfAddresses = new HashSet();
// Setters and Getters Below
}
這裏是我的地址類
@Embeddable
public class Address
{
private String Street;
private String City;
private String State;
private String PinCode;
// Setters and Getters Below
}
我使用的是獨立的Java嘗試將類插入到我的MySQL數據庫中。因爲,對於Hibernate來說我是新手,我只想使用這個註釋,而不是現在的關係。命名HibernateTest.java
public class HibernateTest
{
public static void main(String[] args)
{
UserDetails user = new UserDetails();
Address addr = new Address();
user.setUserId(1);
user.setName("Swateek");
addr.setCity("Berhampur");
addr.setPinCode("760001");
addr.setState("Odisha");
addr.setStreet("RKN");
user.getListOfAddresses().add(addr);
Address addrOff = new Address();
addrOff.setCity("Bangalore");
addrOff.setPinCode("560037");
addrOff.setState("MTH");
addrOff.setStreet("YH");
user.getListOfAddresses().add(addrOff);
SessionFactory sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
session.save(user);
session.getTransaction().commit();
}
}
我獨立的Java類現在,當我運行的類HibernateTest我發現此異常來了。我不知道爲什麼。
Exception in thread "main" org.hibernate.MappingException: Could not determine type for: java.util.Set, for columns:
重複的問題:http://stackoverflow.com/questions/6164123/org-hibernate-mappingexception-could-not-determine-type-for-java-util-set通過使用'java.util.List' – CycDemo
不重複。我想要使用集合。這個集合選擇是一個問題嗎? – swateek
即使我改變了它。我得到了同樣的錯誤。還有其他建議嗎? – swateek