-->
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.  [ 2 posts ] 
Author Message
 Post subject: Mapping @ManyToOne w composite id
PostPosted: Sat Oct 13, 2007 12:45 pm 
Newbie

Joined: Sat Oct 13, 2007 12:42 pm
Posts: 5
I have a Database that i need to persist and that i can't change his structure.

With reverse engineering i created the persistence model, but now i'm with problems:

Class EventActions:


Code:

import javax.persistence.*;
import java.util.Collection;

@Entity
@Table(catalog = "yogurt", schema = "dbx", name = "EventActions")
@IdClass(EventactionsPK.class)
public class Eventactions {
    private int operationintervalid;
    private short eventactionid;
    private short eventtypeid;
    private String eventactionname;
    private Operationinterval operationintervalsByOperationintervalid;

    @ManyToOne
    @JoinColumn(name = "operationIntervalId", referencedColumnName = "operationIntervalId", nullable = false)
    public Operationinterval getOperationintervalsByOperationintervalid() {
        return operationintervalsByOperationintervalid;
    }

    public void setOperationintervalsByOperationintervalid(Operationinterval operationintervalsByOperationintervalid) {
        this.operationintervalsByOperationintervalid = operationintervalsByOperationintervalid;
    }

    @Basic
    @Column(name = "eventActionName", nullable = false, length = 50)
    public String getEventactionname() {
        return eventactionname;
    }

    public void setEventactionname(String eventactionname) {
        this.eventactionname = eventactionname;
    }

    @Basic
    @Column(name = "eventTypeId", nullable = false, length = 5)
    public short getEventtypeid() {
        return eventtypeid;
    }

    public void setEventtypeid(short eventtypeid) {
        this.eventtypeid = eventtypeid;
    }

    @Id
    @Column(name = "eventActionId", nullable = false, length = 5)
    public short getEventactionid() {
        return eventactionid;
    }

    public void setEventactionid(short eventactionid) {
        this.eventactionid = eventactionid;
    }

    @Id
    @Column(name = "operationIntervalId", nullable = false, length = 10)
    public int getOperationintervalid() {
        return operationintervalid;
    }

    public void setOperationintervalid(int operationintervalid) {
        this.operationintervalid = operationintervalid;
    }
}




The Pk Class:

Code:
   
public class EventactionsPK implements Serializable {
    private short eventactionid;
    private int operationintervalid;

    public int getOperationintervalid() {
        return operationintervalid;
    }

    public void setOperationintervalid(int operationintervalid) {
        this.operationintervalid = operationintervalid;
    }

    public short getEventactionid() {
        return eventactionid;
    }

    public void setEventactionid(short eventactionid) {
        this.eventactionid = eventactionid;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        EventactionsPK that = (EventactionsPK) o;

        if (eventactionid != that.eventactionid) return false;
        if (operationintervalid != that.operationintervalid) return false;

        return true;
    }

    public int hashCode() {
        int result;
        result = (int) eventactionid;
        result = 31 * result + operationintervalid;
        return result;
    }
}




The OperationInterval class:
Code:
   

@Entity
@Table(catalog = "yogurt", schema = "dbx", name = "OperationInterval")
public class Operationinterval {
    private int operationintervalid;
    private Timestamp startdate;
    private Timestamp enddate;
    private boolean readytodebrief;
    private int dsnid;
    private Collection<Eventactions> eventactionsByOperationintervalid;

    @OneToMany(mappedBy = "operationintervalsByOperationintervalid")
    public Collection<Eventactions> getEventactionsByOperationintervalid() {
        return eventactionsByOperationintervalid;
    }

    public void setEventactionsByOperationintervalid(Collection<Eventactions> eventactionsByOperationintervalid) {
        this.eventactionsByOperationintervalid = eventactionsByOperationintervalid;
    }


    @Basic
    @Column(name = "dsnId", nullable = false, length = 10)
    public int getDsnid() {
        return dsnid;
    }

    public void setDsnid(int dsnid) {
        this.dsnid = dsnid;
    }

    @Basic
    @Column(name = "readytoDebrief", nullable = false, length = 1)
    public boolean isReadytodebrief() {
        return readytodebrief;
    }

    public void setReadytodebrief(boolean readytodebrief) {
        this.readytodebrief = readytodebrief;
    }

    @Basic
    @Column(name = "endDate", nullable = false, length = 23, precision = 3)
    public Timestamp getEnddate() {
        return enddate;
    }

    public void setEnddate(Timestamp enddate) {
        this.enddate = enddate;
    }

    @Basic
    @Column(name = "startDate", nullable = false, length = 23, precision = 3)
    public Timestamp getStartdate() {
        return startdate;
    }

    public void setStartdate(Timestamp startdate) {
        this.startdate = startdate;
    }

    @Id
    @Column(name = "operationIntervalId", nullable = false, length = 10)
    public int getOperationintervalid() {
        return operationintervalid;
    }

    public void setOperationintervalid(int operationintervalid) {
        this.operationintervalid = operationintervalid;
    }
}




When i validate the model, it gives the error:

org.hibernate.AnnotationException: Column name operationintervalid of Eventactions not found in JoinColumns.referencedColumnName

Stack:

Caused by: org.hibernate.AnnotationException: Column name operationintervalid of com.criticalsoftware.chums.data.entity.hums.HumsBumeventact
ions not found in JoinColumns.referencedColumnName
at org.hibernate.cfg.annotations.TableBinder.bindFk(TableBinder.java:319)
at org.hibernate.cfg.FkSecondPass.doSecondPass(FkSecondPass.java:64)
at org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:474)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:295)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1269)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:150)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:888)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:416)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:126)
at org.ow2.easybeans.persistence.JPersistenceContext.init(JPersistenceContext.java:72)
at org.ow2.easybeans.persistence.JPersistenceContext.<init>(JPersistenceContext.java:65)
at org.ow2.easybeans.persistence.PersistenceUnitManager.addExtraPersistenceUnitInfos(PersistenceUnitManager.java:88)
at org.ow2.easybeans.persistence.PersistenceUnitManager.<init>(PersistenceUnitManager.java:64)
at org.ow2.easybeans.persistence.xml.PersistenceXmlFileAnalyzer.analyzePersistenceXmlFile(PersistenceXmlFileAnalyzer.java:143)
at org.ow2.easybeans.container.JContainer3.start(JContainer3.java:271)
at org.ow2.easybeans.osgi.ejbjar.Activator.startContainer(Activator.java:129)
at org.ow2.easybeans.osgi.ejbjar.Activator.start(Activator.java:91)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl$2.run(BundleContextImpl.java:999)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:993)
... 14 more
Nested Exception:




So... I commented the joincolumn anotation... and the result is:

org.hibernate.HibernateException: Missing column: operationintervalsByOperationintervalid_operationIntervalId in yogurt.dbx.EventActions



How can i solve this problem ? I can't change the database.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 15, 2007 6:12 pm 
Newbie

Joined: Tue Sep 11, 2007 12:17 pm
Posts: 9
Hi, try putting the ColumnName annotations in your PK class.


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

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.