agarwal_achhnera
agarwal_achhnera

Reputation: 2456

why MyEclipse shows join_table not found error at compilation

I have the following two entities but in Trainer at the @OneToMany relation line it shows error message that "join table trainer_batch can not be found", while I am using @JoinColumn annotation. This is my java code:

@Entity
@Table(name="trainer")
public class Trainer {

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    int id;
    String name;
    @OneToMany(cascade=CascadeType.ALL) // this is the line
    @JoinColumn(name="trainerid")
    Set<Batch> batches=new HashSet<Batch>();
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Set<Batch> getBatches() {
        return batches;
    }
    public void setBatches(Batch batch) {
        batches.add(batch);
    }
}

@Entity
@Table(name="batch")
public class Batch {

    public String getSlot() {
        return slot;
    }
    public void setSlot(String slot) {
        this.slot = slot;
    }
    public String getTopic() {
        return topic;
    }
    public void setTopic(String topic) {
        this.topic = topic;
    }
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    int id;
    String slot;
    String topic;
}

persistance.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
    http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
    
    <persistence-unit name="one_to_many_pk_fkPU" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
            <property name = "hibernate.connection.driver_class" value = "com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
            <property name = "hibernate.connection.url" value = "jdbc:sqlserver://localhost:1433;DatabaseName=test; MARS_Connection=yes;"/>
            <property name = "hibernate.connection.username" value = "sa"/>
            <property name = "hibernate.connection.password" value = "test"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
        </properties>
    </persistence-unit>
  
</persistence>

Upvotes: 1

Views: 164

Answers (1)

Kanagaraj M
Kanagaraj M

Reputation: 966

you should use generic as Batch . User your relation like this: Set<Batch> batches=new HashSet<Batch>();

Upvotes: 0

Related Questions