开发者

hibernate mapping for Object

开发者 https://www.devze.com 2023-03-09 12:40 出处:网络
public class ID { protected String name; protected Object id; } How c开发者_高级运维an I map the above class in hibernate, if I were to use ID.hbm.xml ? Is this possible ?Instead of using xml, you c
public class ID {
    protected String name;
    protected Object id;
}

How c开发者_高级运维an I map the above class in hibernate, if I were to use ID.hbm.xml ? Is this possible ?


Instead of using xml, you can use annotations:

@Entity
public class ID {
    @Id
    private Object id;
    @Column
    private String name;
    // getters and setters
}

Btw, ID is a strange name for an entity.

In XML you would need something like this (reference):

<class ...>
    <id .. />
    <property .. />
</class>

The type of the id field depends entirely on your requirements - most often it is an auto-generated int (using the @GeneratedValue annotation). But it can be a String, or any manually-assigned, database-persistable type.

0

精彩评论

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