-->
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.  [ 8 posts ] 
Author Message
 Post subject: not found in JoinColumns.referencedColumnName
PostPosted: Tue Feb 20, 2007 1:19 pm 
Beginner
Beginner

Joined: Tue Jun 06, 2006 3:37 am
Posts: 29
Hi,

I'm facing a problem while I'm trying to deploy my application

here's my db schema

[code]
DROP TABLE IF EXISTS `type`;
CREATE TABLE `type` (
`id_type` int(4) NOT NULL AUTO_INCREMENT,
`text` text NOT NULL,
PRIMARY KEY (`id_type`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

DROP TABLE IF EXISTS `lang`;
CREATE TABLE `lang` (
`id_lang` int(4) NOT NULL AUTO_INCREMENT,
`name` text NOT NULL,
PRIMARY KEY (`id_lang`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

DROP TABLE IF EXISTS `message`;
CREATE TABLE `message` (
`id_message` int NOT NULL,
`text` text NOT NULL,
`ref_type` int(4),
`ref_lang` int(2) NOT NULL,
FOREIGN KEY `FK_MESSAGE_TYPE` (`ref_type`) REFERENCES `type` (`id_type`),
PRIMARY KEY (`id_message`,`ref_lang`),
FOREIGN KEY `FK_MESSAGE_LANG` (`ref_lang`) REFERENCES `lang` (`id_lang`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


[/code]

And my entity message got

[code]
@EmbeddedId
protected MessagePK messagePK;

@Lob
@Column(name = "text", nullable = false)
private String text;

@JoinColumn(name = "ref_type", referencedColumnName = "id_type")
@ManyToOne
private Type refType;

@JoinColumn(name = "ref_lang", referencedColumnName = "id_lang")
@ManyToOne(targetEntity=Lang.class)
private Lang refLang;

[/code]


The complete error message is

[code]
Bind entity com.recordz.ejb.entity.Type on table type
Column name ref_lang of com.recordz.ejb.entity.Message not found in JoinColumns.referencedColumnName
org.hibernate.AnnotationException: Column name ref_lang of com.recordz.ejb.entity.Message not found in JoinColumns.referencedColumnName

[/code]

Is there a problem with ref_lang because it's a foreign key and he's part of the composite primary key ?

Regards[code][/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 20, 2007 8:20 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
you don't show enough, incl the full pojo code

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 21, 2007 4:26 am 
Beginner
Beginner

Joined: Tue Jun 06, 2006 3:37 am
Posts: 29
Well, here is the full Message POJO

Code:
/*
* Message.java
*
* Created on 21. février 2007, 09:22
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package com.recordz.ejb.entity;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
* Entity class Message
*
* @author alex
*/
@Entity
@Table(name = "message")
@NamedQueries( {
        @NamedQuery(name = "Message.findByIdMessage", query = "SELECT m FROM Message m WHERE m.messagePK.idMessage = :idMessage"),
        @NamedQuery(name = "Message.findByRefLang", query = "SELECT m FROM Message m WHERE m.messagePK.refLang = :refLang")
    })
public class Message implements Serializable {

    /**
     * EmbeddedId primary key field
     */
    @EmbeddedId
    protected MessagePK messagePK;

    @Lob
    @Column(name = "text", nullable = false)
    private String text;

    @JoinColumn(name = "ref_type", referencedColumnName = "id_type")
    @ManyToOne
    private Type refType;

    @JoinColumn(name = "ref_lang", referencedColumnName = "id_lang", insertable = false, updatable = false)
    @ManyToOne
    private Lang lang;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "message")
    private Collection<Category> categoryCollection;
   
    /** Creates a new instance of Message */
    public Message() {
    }

    /**
     * Creates a new instance of Message with the specified values.
     * @param messagePK the messagePK of the Message
     */
    public Message(MessagePK messagePK) {
        this.messagePK = messagePK;
    }

    /**
     * Creates a new instance of Message with the specified values.
     * @param messagePK the messagePK of the Message
     * @param text the text of the Message
     */
    public Message(MessagePK messagePK, String text) {
        this.messagePK = messagePK;
        this.text = text;
    }

    /**
     * Creates a new instance of MessagePK with the specified values.
     * @param refLang the refLang of the MessagePK
     * @param idMessage the idMessage of the MessagePK
     */
    public Message(int refLang, int idMessage) {
        this.messagePK = new MessagePK(refLang, idMessage);
    }

    /**
     * Gets the messagePK of this Message.
     * @return the messagePK
     */
    public MessagePK getMessagePK() {
        return this.messagePK;
    }

    /**
     * Sets the messagePK of this Message to the specified value.
     * @param messagePK the new messagePK
     */
    public void setMessagePK(MessagePK messagePK) {
        this.messagePK = messagePK;
    }

    /**
     * Gets the text of this Message.
     * @return the text
     */
    public String getText() {
        return this.text;
    }

    /**
     * Sets the text of this Message to the specified value.
     * @param text the new text
     */
    public void setText(String text) {
        this.text = text;
    }

    /**
     * Gets the refType of this Message.
     * @return the refType
     */
    public Type getRefType() {
        return this.refType;
    }

    /**
     * Sets the refType of this Message to the specified value.
     * @param refType the new refType
     */
    public void setRefType(Type refType) {
        this.refType = refType;
    }

    /**
     * Gets the lang of this Message.
     * @return the lang
     */
    public Lang getLang() {
        return this.lang;
    }

    /**
     * Sets the lang of this Message to the specified value.
     * @param lang the new lang
     */
    public void setLang(Lang lang) {
        this.lang = lang;
    }

    /**
     * Gets the categoryCollection of this Message.
     * @return the categoryCollection
     */
    public Collection<Category> getCategoryCollection() {
        return this.categoryCollection;
    }

    /**
     * Sets the categoryCollection of this Message to the specified value.
     * @param categoryCollection the new categoryCollection
     */
    public void setCategoryCollection(Collection<Category> categoryCollection) {
        this.categoryCollection = categoryCollection;
    }

    /**
     * Returns a hash code value for the object.  This implementation computes
     * a hash code value based on the id fields in this object.
     * @return a hash code value for this object.
     */
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (this.messagePK != null ? this.messagePK.hashCode() : 0);
        return hash;
    }

    /**
     * Determines whether another object is equal to this Message.  The result is
     * <code>true</code> if and only if the argument is not null and is a Message object that
     * has the same id field values as this object.
     * @param object the reference object with which to compare
     * @return <code>true</code> if this object is the same as the argument;
     * <code>false</code> otherwise.
     */
    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Message)) {
            return false;
        }
        Message other = (Message)object;
        if (this.messagePK != other.messagePK && (this.messagePK == null || !this.messagePK.equals(other.messagePK))) return false;
        return true;
    }

    /**
     * Returns a string representation of the object.  This implementation constructs
     * that representation based on the id fields.
     * @return a string representation of the object.
     */
    @Override
    public String toString() {
        return "com.recordz.ejb.entity.Message[messagePK=" + messagePK + "]";
    }
   
}



MessagePK :

Code:
/*
* MessagePK.java
*
* Created on 21. février 2007, 09:22
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package com.recordz.ejb.entity;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Embeddable;

/**
* Primary Key class MessagePK for entity class Message
*
* @author alex
*/
@Embeddable
public class MessagePK implements Serializable {

    @Column(name = "id_message", nullable = false)
    private int idMessage;

    @Column(name = "ref_lang", nullable = false)
    private int refLang;
   
    /** Creates a new instance of MessagePK */
    public MessagePK() {
    }

    /**
     * Creates a new instance of MessagePK with the specified values.
     * @param refLang the refLang of the MessagePK
     * @param idMessage the idMessage of the MessagePK
     */
    public MessagePK(int refLang, int idMessage) {
        this.refLang = refLang;
        this.idMessage = idMessage;
    }

    /**
     * Gets the idMessage of this MessagePK.
     * @return the idMessage
     */
    public int getIdMessage() {
        return this.idMessage;
    }

    /**
     * Sets the idMessage of this MessagePK to the specified value.
     * @param idMessage the new idMessage
     */
    public void setIdMessage(int idMessage) {
        this.idMessage = idMessage;
    }

    /**
     * Gets the refLang of this MessagePK.
     * @return the refLang
     */
    public int getRefLang() {
        return this.refLang;
    }

    /**
     * Sets the refLang of this MessagePK to the specified value.
     * @param refLang the new refLang
     */
    public void setRefLang(int refLang) {
        this.refLang = refLang;
    }

    /**
     * Returns a hash code value for the object.  This implementation computes
     * a hash code value based on the id fields in this object.
     * @return a hash code value for this object.
     */
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (int)refLang;
        hash += (int)idMessage;
        return hash;
    }

    /**
     * Determines whether another object is equal to this MessagePK.  The result is
     * <code>true</code> if and only if the argument is not null and is a MessagePK object that
     * has the same id field values as this object.
     * @param object the reference object with which to compare
     * @return <code>true</code> if this object is the same as the argument;
     * <code>false</code> otherwise.
     */
    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof MessagePK)) {
            return false;
        }
        MessagePK other = (MessagePK)object;
        if (this.refLang != other.refLang) return false;
        if (this.idMessage != other.idMessage) return false;
        return true;
    }

    /**
     * Returns a string representation of the object.  This implementation constructs
     * that representation based on the id fields.
     * @return a string representation of the object.
     */
    @Override
    public String toString() {
        return "com.recordz.ejb.entity.MessagePK[refLang=" + refLang + ", idMessage=" + idMessage + "]";
    }
   
}



Lang POJO

Code:
/*
* Lang.java
*
* Created on 21. février 2007, 09:22
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package com.recordz.ejb.entity;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
* Entity class Lang
*
* @author alex
*/
@Entity
@Table(name = "lang")
@NamedQueries( {
        @NamedQuery(name = "Lang.findByIdLang", query = "SELECT l FROM Lang l WHERE l.idLang = :idLang")
    })
public class Lang implements Serializable {

    @Id
    @Column(name = "id_lang", nullable = false)
    private Integer idLang;

    @Lob
    @Column(name = "name", nullable = false)
    private String name;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "lang")
    private Collection<Message> messageCollection;
   
    /** Creates a new instance of Lang */
    public Lang() {
    }

    /**
     * Creates a new instance of Lang with the specified values.
     * @param idLang the idLang of the Lang
     */
    public Lang(Integer idLang) {
        this.idLang = idLang;
    }

    /**
     * Creates a new instance of Lang with the specified values.
     * @param idLang the idLang of the Lang
     * @param name the name of the Lang
     */
    public Lang(Integer idLang, String name) {
        this.idLang = idLang;
        this.name = name;
    }

    /**
     * Gets the idLang of this Lang.
     * @return the idLang
     */
    public Integer getIdLang() {
        return this.idLang;
    }

    /**
     * Sets the idLang of this Lang to the specified value.
     * @param idLang the new idLang
     */
    public void setIdLang(Integer idLang) {
        this.idLang = idLang;
    }

    /**
     * Gets the name of this Lang.
     * @return the name
     */
    public String getName() {
        return this.name;
    }

    /**
     * Sets the name of this Lang to the specified value.
     * @param name the new name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * Gets the messageCollection of this Lang.
     * @return the messageCollection
     */
    public Collection<Message> getMessageCollection() {
        return this.messageCollection;
    }

    /**
     * Sets the messageCollection of this Lang to the specified value.
     * @param messageCollection the new messageCollection
     */
    public void setMessageCollection(Collection<Message> messageCollection) {
        this.messageCollection = messageCollection;
    }

    /**
     * Returns a hash code value for the object.  This implementation computes
     * a hash code value based on the id fields in this object.
     * @return a hash code value for this object.
     */
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (this.idLang != null ? this.idLang.hashCode() : 0);
        return hash;
    }

    /**
     * Determines whether another object is equal to this Lang.  The result is
     * <code>true</code> if and only if the argument is not null and is a Lang object that
     * has the same id field values as this object.
     * @param object the reference object with which to compare
     * @return <code>true</code> if this object is the same as the argument;
     * <code>false</code> otherwise.
     */
    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Lang)) {
            return false;
        }
        Lang other = (Lang)object;
        if (this.idLang != other.idLang && (this.idLang == null || !this.idLang.equals(other.idLang))) return false;
        return true;
    }

    /**
     * Returns a string representation of the object.  This implementation constructs
     * that representation based on the id fields.
     * @return a string representation of the object.
     */
    @Override
    public String toString() {
        return "com.recordz.ejb.entity.Lang[idLang=" + idLang + "]";
    }
   
}



Thanks for your support Emmanuel.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 21, 2007 3:37 pm 
Beginner
Beginner

Joined: Tue Jun 06, 2006 3:37 am
Posts: 29
I thing JPA doesn't really support relation of this kind ... the only way I know to solve this problem is to delete the mapping between tables, use a simple int reference to join the table ...

@Column(name = "ref_lang", nullable = false)
private int refLang;

become

private int refLang;


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 27, 2007 6:47 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Can you show the Type POJO too, I don't realy udnerstand why it fails

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 28, 2007 7:51 am 
Beginner
Beginner

Joined: Tue Jun 06, 2006 3:37 am
Posts: 29
Sure,

Here we are

Code:
/*
* Type.java
*
* Created on 20. février 2007, 18:45
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package com.recordz.ejb.entity;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
* Entity class Type
*
* @author alex
*/
@Entity
@Table(name = "type")
@NamedQueries( {
        @NamedQuery(name = "Type.findByIdType", query = "SELECT t FROM Type t WHERE t.idType = :idType")
    })
public class Type implements Serializable {

    @Id
    @Column(name = "id_type", nullable = false)
    private Integer idType;

    @Lob
    @Column(name = "text", nullable = false)
    private String text;

    @OneToMany(mappedBy = "refType")
    private Collection<Message> messageCollection;
   
    /** Creates a new instance of Type */
    public Type() {
    }

    /**
     * Creates a new instance of Type with the specified values.
     * @param idType the idType of the Type
     */
    public Type(Integer idType) {
        this.idType = idType;
    }

    /**
     * Creates a new instance of Type with the specified values.
     * @param idType the idType of the Type
     * @param text the text of the Type
     */
    public Type(Integer idType, String text) {
        this.idType = idType;
        this.text = text;
    }

    /**
     * Gets the idType of this Type.
     * @return the idType
     */
    public Integer getIdType() {
        return this.idType;
    }

    /**
     * Sets the idType of this Type to the specified value.
     * @param idType the new idType
     */
    public void setIdType(Integer idType) {
        this.idType = idType;
    }

    /**
     * Gets the text of this Type.
     * @return the text
     */
    public String getText() {
        return this.text;
    }

    /**
     * Sets the text of this Type to the specified value.
     * @param text the new text
     */
    public void setText(String text) {
        this.text = text;
    }

    /**
     * Gets the messageCollection of this Type.
     * @return the messageCollection
     */
    public Collection<Message> getMessageCollection() {
        return this.messageCollection;
    }

    /**
     * Sets the messageCollection of this Type to the specified value.
     * @param messageCollection the new messageCollection
     */
    public void setMessageCollection(Collection<Message> messageCollection) {
        this.messageCollection = messageCollection;
    }

    /**
     * Returns a hash code value for the object.  This implementation computes
     * a hash code value based on the id fields in this object.
     * @return a hash code value for this object.
     */
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (this.idType != null ? this.idType.hashCode() : 0);
        return hash;
    }

    /**
     * Determines whether another object is equal to this Type.  The result is
     * <code>true</code> if and only if the argument is not null and is a Type object that
     * has the same id field values as this object.
     * @param object the reference object with which to compare
     * @return <code>true</code> if this object is the same as the argument;
     * <code>false</code> otherwise.
     */
    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Type)) {
            return false;
        }
        Type other = (Type)object;
        if (this.idType != other.idType && (this.idType == null || !this.idType.equals(other.idType))) return false;
        return true;
    }

    /**
     * Returns a string representation of the object.  This implementation constructs
     * that representation based on the id fields.
     * @return a string representation of the object.
     */
    @Override
    public String toString() {
        return "com.recordz.ejb.entity.Type[idType=" + idType + "]";
    }
   
}



Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 01, 2007 3:05 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
It should work, which version of Annotations are you using?
Can you give it a try with he latest svn version
http://www.hibernate.org/6.html#A3
http://www.hibernate.org/6.html#A5 (replace metadata with annotations)

If it fails, wrap your classes into a test case and post it to JIRA, I'll have to give it a look

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 04, 2007 5:30 pm 
Beginner
Beginner

Joined: Tue Jun 06, 2006 3:37 am
Posts: 29
Thanks Emmanuel,

I checked out hibernate3 and hibernateExt, I succefully did the hibernate3 compilation but I didn't find any metadata folder under the hibernateExt directory.

Here is the correct guidline to build annotation + entity manager

This will create a directory {%ROOT_DIR%}/hibernate3.2

Then go to {%ROOT_DIR%}/HibernateExt/ and run:

* ant jar to compile and create hibernate-annotations.jar
* ant junitreport to run tests using HSQL and report to test_output
* ant clean to clean up

To compile Hibernate EntityManager, copy hibernate-annotations.jar from {%ROOT_DIR%}/HibernateExt/annotations/target/hibernate-annotations(after ant jar has been run) to {%ROOT_DIR%}/HibernateExt/entitymanager/lib

Then go to {%ROOT_DIR%}/HibernateExt/entitymanager and run:

* ant jar to compile and create hibernate-entitymanager.jar
* ant junitreport to run tests using HSQL and report to test_output
* ant clean to clean up

Before replacing the *jar I want to be sure, they are a lot's of difference between the content of the old hibernate-annotation.jar files

the new is on the left and the old on the rigth

Here is a screen capture
Image

Is that normal ???


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.