我想知道一个类的一些成员变量的注释,我BeanInfo beanInfo = Introspector.getBeanInfo(User.class)用来内省一个类,并使用BeanInfo.getPropertyDescriptors(),找到特定的属性,并使用Class type = propertyDescriptor.getPropertyType()来获取属性的类.
但我不知道如何将注释添加到成员变量中?
我试过了type.getAnnotations(),type.getDeclaredAnnotations()但是,两者都返回了Class的注释,而不是我想要的.例如 :
class User
{
@Id
private Long id;
@Column(name="ADDRESS_ID")
private Address address;
// getters , setters
}
@Entity
@Table(name = "Address")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
class Address
{
...
}
Run Code Online (Sandbox Code Playgroud)
我想得到地址的注释:@Column,而不是类地址的注释(@ Entity,@ Table,@ Cache).怎么实现呢?谢谢.
有谁知道我怎么能在休眠中做相同的事情:
session.getIdentifier(instance);
Run Code Online (Sandbox Code Playgroud)
与JPA?
EntityManager有一个contains方法,但就是这样!
我正在编写一些代码,它们充当实体和存储在会话中的数据之间的转换器(因此,而不是仅存储类名并且存储id的序列化对象).