wxlfrank
wxlfrank

Reputation: 39

Does Class name matter during ORM process?

I have defined 3 classes as follows: I tried to generate the schema in MySQL. It won't succeed. But the wired thing is after I have renamed one class, CerifLink--->MyLink, it works.

Can anyone give a reasonable explanation?

    package org.epos.grdb.jpa.entity;

        import java.io.Serializable;

        import javax.persistence.ConstraintMode;
        import javax.persistence.Entity;
        import javax.persistence.ForeignKey;
        import javax.persistence.Id;
        import javax.persistence.JoinColumn;
        import javax.persistence.JoinColumns;
        import javax.persistence.ManyToOne;

        @Entity
        public class CerifLink implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = -9162577962410473641L;
    @Id
    @ManyToOne
    @JoinColumns(value = { @JoinColumn(referencedColumnName = "id"),
            @JoinColumn(referencedColumnName = "cfid") }, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, foreignKeyDefinition = "foreign key (`cfClassId`) references `cfClass` (`cfClassId`)"))
    private Class clazz;

    public Class getClazz() {
        return clazz;
    }

    public void setClazz(Class clazz) {
        this.clazz = clazz;
    }

}

package org.epos.grdb.jpa.entity;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class MyEntity implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 5185624925049306788L;
    @Id
    protected String id;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}
package org.epos.grdb.jpa.entity;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

@Entity
public class Class implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1573828246619342971L;
    @Id
    protected String id;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Id
    @ManyToOne
    @JoinColumn(name = "cfid", referencedColumnName = "id")
    private MyEntity classSchema;

    public MyEntity getClassSchema() {
        return classSchema;
    }

    public void setClassSchema(MyEntity classSchema) {
        this.classSchema = classSchema;
    }

}

But the wired thing is after I have renamed one class, CerifLink--->MyLink, it works.

Can anyone give a reasonable explanation?

Upvotes: 1

Views: 95

Answers (1)

pixelatedCat
pixelatedCat

Reputation: 312

Yes class name matter, you should check the NamingStrategy of Hibernate, you can modify it depending on the hibernate version you are using, but for what are you doing I guess you can use the annotation table and assign a specific name

@Table(name = "myname")

Upvotes: 2

Related Questions