休眠。本地化列。动态加载

时间:2016-07-31 07:30:53

标签: java hibernate internationalization

我有一个包含列的表国家/地区:

id, en, de, fr, ru, lt

id - primary key
en,de,... - localization

我想写实体,如:

@Entity
@Table(name = "countries")
public class EntityCountry {
    @Id
    @Column(name = "id")
    @GeneratedValue
    private int id;

    @Localization
    private String name;

让实体像:

Session session = HibernateUtils.getSessionFactory().openSession();
session.beginTransaction();
EntityCountry e = (EntityCountry) session.createQuery("from EntityCountry where id = 1").setLocalization("en").uniqueResult();
session.getTransaction().commit();
session.close();

请帮助我如何做到这一点?

0 个答案:

没有答案