Does Class mame 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;
    }

}

What error do you get?

Also, why does the Class entity has both an @Id and another @Id for the classSchema?

The error says “cannot find the logical name ‘cfid’ in class”

The class itself has an identitier and it referes to an classschema which is a foreign key.

CerifLink has a referenceColumn to cfid but Class does not has that column. That’s the problem.

But @JoinColumn(name = “cfid”, referencedColumnName = “id”) defines a cfid column in Class.

Besides, I change the name of the class and it works.

I have tried other classes I defined. I find the same problem. I suspect that the class name determines the order of being processed during orm mapping. This may affects the result.