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.
精彩评论