Java 有条件地排序会导致休眠
这是我正在使用的桌子。有一个用户表,其中包含一些预定义的列(“下例中的名称”),还有一个额外的属性表,用于使架构扩展成为可能。额外属性表将任何新扩展属性的值存储为键值对(“title”和“mobile”是以下示例中的额外属性),“user”列用于与主用户表联接。这种安排通常适用于大多数操作,但我想不出一种方法来对用户的任何额外属性进行排序Java 有条件地排序会导致休眠,java,sql,hibernate,Java,Sql,Hibernate,这是我正在使用的桌子。有一个用户表,其中包含一些预定义的列(“下例中的名称”),还有一个额外的属性表,用于使架构扩展成为可能。额外属性表将任何新扩展属性的值存储为键值对(“title”和“mobile”是以下示例中的额外属性),“user”列用于与主用户表联接。这种安排通常适用于大多数操作,但我想不出一种方法来对用户的任何额外属性进行排序 User Table: --------------- id name ============== 1 jon 2
User Table:
---------------
id name
==============
1 jon
2 harry
Extra attributes table:
--------------------------------
user attr_key attr_value
================================
1 title engineer
1 mobile 111-2222-4444
2 title manager
2 mobile 111-0000-5555
Result of joining the two tables above(few columns intentionally skipped):
--------------------------------------------
id name attr_key attr_value
============================================
1 jon title engineer
1 jon mobile 111-2222-4444
2 harry title manager
2 harry mobile 111-0000-5555
我正在使用hibernate进行ORM。以下是实体类:
@Entity
public class User {
private Long id;
private String name;
private Set<ExtraAttributes> extraAttributes;
public String getName() {}
@OneToMany(mappedBy="user",fetch=FetchType.EAGER)
public Set<ExtraAttributes> getExtraAttributes() {}
...
}
@Entity
public class ExtraAttribute {
private Long id;
private String attrKey;
private String attrValue;
private User user;
...
@ManyToOne(optional = false)
public User getUser() {}
...
}
@实体
公共类用户{
私人长id;
私有字符串名称;
私有集属性;
公共字符串getName(){}
@OneToMany(mappedBy=“user”,fetch=FetchType.EAGER)
公共集getExtraAttributes(){}
...
}
@实体
公共类外部属性{
私人长id;
私钥;
私有字符串属性值;
私人用户;
...
@多通(可选=假)
公共用户getUser(){}
...
}
我希望能够按照与特定属性键(比如“title”)对应的属性值对结果进行排序。问题是,如果我按attr_值对结果进行排序,那么将考虑所有attr_值,而我只想按与特定attr_键-“title”对应的attr_值进行排序。我考虑过按attr_键和attr_值进行排序,但这似乎也不能解决问题