开发者

How to configure table generator for sub classes in hibernate annotation?

I am creating a app with hibernate as ORM tool and annotations are used for configuring JPA metadata. Now, I am facing some issues with ID generator for entities. My entities are.

@MappedSuperclass
public class IdentityEntity {

@Id
@Column(name = "id")
@TableGenerator(name = "id_generator", table = "db_index", pkColumnName = "id", valueColumnName = "manuitemid", pkColumnValue = "id", allocationSize = 1, initialValue=1000)
@GeneratedValue(strategy = GenerationType.TABLE, generator = "id_generator")
private long id;

public long getId() {
    return id;
}

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

In this scenario, whenever tis IdentityEntity will be used as parent class for any entity. The Id generator will use the same column name for generating IDs f开发者_如何转开发or all entities. I tries to put id generator on other entities, with different column name. But hibernate returns a error message that the new column name is not found. As below:

ERROR MultipleHiLoPerTableGenerator - could not read or init a hi value
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'menuitemid' in 'field list'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

I want to change this behavior and create a ID generator for every entity separately. What options do I Have?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜