I am trying to follow the pattern in Chapter 7 of Java Persistence with Hibernate (Listing 7.1). This is being used to reverse engineer a legacy database running on Oracle 10g r2.
I am getting the following error message when I start my application:
org.hibernate.MappingException: Could not determine type for: example.Customer, at table: CUSTVISIBILITY, for columns: [org.hibernate.mapping.Column(customer)]
Here are the relevant (simplified) files:
Code:
@Entity
@Table(schema="FRAG_MGR",name="CUSTVISIBILITY")
public class CustomerVisibility {
public CustomerVisibility() {
}
public CustomerVisibility(Customer customer, User username) {
setCustomer(customer);
setUsername(username);
this.id.custid = customer.getId();
this.id.username = username.getId();
customer.getCustomerVisibilities().add(this);
username.getCustomerVisibilities().add(this);
}
@Embeddable
public static class Id implements Serializable {
@Column(name="CUSTID",length=12,nullable=false,insertable=false,updatable=false)
private Long custid;
@Column(name="USERNAME",length=30,nullable=false,insertable=false,updatable=false)
private String username;
public Id() { }
public Id(Long custid, String username) {
this.custid = custid;
this.username = username;
}
public boolean equals(Object o) {
if ( o != null && o instanceof Id) {
Id that = (Id)o;
return this.custid.equals(that.custid) && this.username.equals(that.username);
} else {
return false;
}
}
public int hashCode() {
return custid.hashCode() + username.hashCode();
}
}
@EmbeddedId
private Id id = new Id();
@ManyToOne(targetEntity=Customer.class)
@JoinColumn(name="CUSTID",nullable=false,insertable=false,updatable=false)
public Customer getCustomer() {
return customer;
}
private void setCustomer(Customer customer) {
this.customer = customer;
}
private Customer customer;
@ManyToOne(targetEntity=User.class)
@JoinColumn(name="USERNAME",nullable=false,insertable=false,updatable=false)
public User getUsername() {
return username;
}
private void setUsername(User username) {
this.username = username;
}
private User username;
}
@Entity
@Table(schema="FRAG_MGR",name="CUSTHDR")
public class Customer {
public Customer() {
}
@Id
@GeneratedValue(strategy=GenerationType.AUTO, generator = "seq")
@SequenceGenerator(name="seq", sequenceName = "FRAG_MGR.TRIFOIL_SEQ")
@Column(name="CUSTID",length=12,nullable=false,insertable=false,updatable=false)
public Long getId() {
return id;
}
private void setId(Long id) {
this.id = id;
}
private Long id;
@OneToMany(mappedBy="customer")
public Set<CustomerContact> getCustomerContacts() {
return customercontacts;
}
public void setCustomerContacts(Set<CustomerContact> customercontacts) {
this.customercontacts = customercontacts;
}
private Set<CustomerContact> customercontacts = new HashSet<CustomerContact>();
public void addCustomerContact(CustomerContact a) {
a.setCustomer(this);
customercontacts.add(a);
}
@OneToMany(mappedBy="customer")
public Set<CustomerVisibility> getCustomerVisibilities() {
return customervisibilities;
}
public void setCustomerVisibilities(Set<CustomerVisibility> customervisibilities) {
this.customervisibilities = customervisibilities;
}
private Set<CustomerVisibility> customervisibilities = new HashSet<CustomerVisibility>();
public static Customer get(Serializable id) {
return (Customer)HibernateUtil.getSession().get(Customer.class, id);
}
}
@Entity
@Table(schema="FRAG_MGR",name="CUSTCONTACT")
public class CustomerContact {
public CustomerContact() {
}
@Id
@GeneratedValue(strategy=GenerationType.AUTO, generator = "seq")
@SequenceGenerator(name="seq", sequenceName = "FRAG_MGR.TRIFOIL_SEQ")
@Column(name="CUSTCONTACTID",length=12,nullable=false,insertable=false,updatable=false)
public Long getId() {
return id;
}
private void setId(Long id) {
this.id = id;
}
private Long id;
@ManyToOne(targetEntity=Customer.class)
@JoinColumn(name="CUSTID",nullable=false,insertable=true,updatable=true)
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
private Customer customer;
}
@Entity
@Table(schema="FRAG_MGR",name="TRIUSERS")
public class User {
public User() {
}
@Id
@GeneratedValue(strategy=GenerationType.AUTO, generator = "seq")
@SequenceGenerator(name="seq", sequenceName = "FRAG_MGR.TRIFOIL_SEQ")
@Column(name="USERNAME",length=30,nullable=false,insertable=false,updatable=false)
public String getId() {
return id;
}
private void setId(String id) {
this.id = id;
}
private String id;
@OneToMany(mappedBy="username")
public Set<CustomerVisibility> getCustomerVisibilities() {
return customervisibilities;
}
public void setCustomerVisibilities(Set<CustomerVisibility> customervisibilities) {
this.customervisibilities = customervisibilities;
}
private Set<CustomerVisibility> customervisibilities = new HashSet<CustomerVisibility>();
public static User get(Serializable id) {
return (User)HibernateUtil.getSession().get(User.class, id);
}
}
Any help would be very appreciated!
Carl