如何使用 HQL 获取组合列名
How to get combine Column name using HQL
我有两个跟随 Java 实体
@Entity(table="user_profiles")
class Profile{
@Column(name="id")
@Id
@GeneratedValue
private Integer id;
@Column(name="first_name")
private String firstName;
@Column(name="last_name")
private String lastName;
}
和
@Entity
@Table(name="threads")
class Thread {
@Column(name="thread_id")
@Id
@GeneratedValue
private Integer threadId;
@Column(name="to_profile_name")
private String toProfileFullName;
@Column(name="from_profile_name")
private String fromProfileFullName;
@Column(name="to_profile_id")
private Integer toProfileId;
@Column(name="from_profile_id")
private Integer fromProfileId;
}
我需要用配置文件的名字+姓氏填充 toProfileFullName 和 fromProfileFullName class,fromProfileId 和 toProfileId 是配置文件 class 的外键,有没有办法使用 HQL?还是跟Hibernate有关系?
您需要在 Profile
和 Thread
之间创建映射。根据您的数据模型查找 OneToOne
、OneToMany
、ManyToOne
和 ManyToMany
。
然后我将在 Thread
中创建瞬态 getter,这将简单地 return getProfile().getFirstName() + getProfile.getLastName()
。
我有两个跟随 Java 实体
@Entity(table="user_profiles")
class Profile{
@Column(name="id")
@Id
@GeneratedValue
private Integer id;
@Column(name="first_name")
private String firstName;
@Column(name="last_name")
private String lastName;
}
和
@Entity
@Table(name="threads")
class Thread {
@Column(name="thread_id")
@Id
@GeneratedValue
private Integer threadId;
@Column(name="to_profile_name")
private String toProfileFullName;
@Column(name="from_profile_name")
private String fromProfileFullName;
@Column(name="to_profile_id")
private Integer toProfileId;
@Column(name="from_profile_id")
private Integer fromProfileId;
}
我需要用配置文件的名字+姓氏填充 toProfileFullName 和 fromProfileFullName class,fromProfileId 和 toProfileId 是配置文件 class 的外键,有没有办法使用 HQL?还是跟Hibernate有关系?
您需要在 Profile
和 Thread
之间创建映射。根据您的数据模型查找 OneToOne
、OneToMany
、ManyToOne
和 ManyToMany
。
然后我将在 Thread
中创建瞬态 getter,这将简单地 return getProfile().getFirstName() + getProfile.getLastName()
。