-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: mapping a join table with an intermediate entity
PostPosted: Wed Sep 24, 2008 11:46 pm 
Newbie

Joined: Thu Oct 12, 2006 3:15 pm
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.