Here's the code.
Code:
package ch7;
import java.util.HashMap;
import java.util.Map;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
public class Account {
private String name;
private String address;
private String telephone;
private String creditCardNumber;
private Map<String, Integer> items = new HashMap<String, Integer>();
private Long id;
public Account() {
}
@ElementCollection
public Map<String, Integer> getItems() {
return items;
}
public void setItems(Map<String, Integer> items) {
this.items = items;
}
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String Name) {
this.name = Name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getTelephone() {
return telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
public String getCreditCardNumber() {
return creditCardNumber;
}
public void setCreditCardNumber(String creditCardNumber) {
this.creditCardNumber = creditCardNumber;
}
}
Here's the stacktrace
Code:
org.hibernate.MappingException: Could not determine type for: java.util.Map, for columns: [org.hibernate.mapping.Column(items)]
org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266)
org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
org.hibernate.mapping.Property.isValid(Property.java:185)
org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:440)
org.hibernate.mapping.RootClass.validate(RootClass.java:192)
org.hibernate.cfg.Configuration.validate(Configuration.java:1102)
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1287)
org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
shared.HibernateHelper.createFactory(HibernateHelper.java:176)
shared.HibernateHelper.createTable(HibernateHelper.java:149)
shared.HibernateHelper.createTable(HibernateHelper.java:155)
ch7.CartController.init(CartController.java:28)
javax.servlet.GenericServlet.init(GenericServlet.java:160)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:498)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:394)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
java.lang.Thread.run(Thread.java:619)
I've read the Documentation closely and adding @ElementCollection seems to be all I should need to do here. I'm also using netbeans and read that there was a bug that you needed to make sure you were using hibernate > 3.5 so created a new Persistence Unit to do this but I hasn't changed anything. I've also tried moving the annotations from getters to the fields but this didn't make any difference either. What is it I'm missing?