简体   繁体   English

JPA-将实体映射到sql查询吗?

[英]JPA - map entity to sql query?

I'm writing a JPA connector to a legacy sistem. 我正在将JPA连接器编写到旧系统。 The problem is, DB design in the system is.. well.. horrible. 问题是,系统中的DB设计非常糟糕。

I need to implement an entity that maps to three tables. 我需要实现一个映射到三个表的实体。 I can do it using named sql queries, but the probem is, I have to use this entity in a OneToMany relation (this entity is on the many side). 我可以使用命名的sql查询来做到这一点,但探查性是,我必须在OneToMany关系中使用此实体(该实体在许多方面)。 So how do I tell JPA it needs to use a specific named query with specific parameter? 那么如何告诉JPA它需要使用带有特定参数的特定命名查询?

And a subquestion: does any1 have any good on-line JPA documentation? 还有一个子问题:any1是否有任何好的在线JPA文档? I can't find anything decent :-/ 我找不到任何体面的:-/

I haven't actually found a way to do this with JPA. 我实际上还没有找到使用JPA做到这一点的方法。 To solve problems like this I ended up using a named query. 为了解决这样的问题,我最终使用了命名查询。

As far as documentation, I have been using TopLink's and Hibernate's . 就文档而言,我一直在使用TopLinkHibernate的

If you find a better way, please post it here! 如果您找到更好的方法,请在此处发布!

Take a look at @SecondaryTable(s). 看看@SecondaryTable(s)。 There's some examples of this in the Pro EJB 3 Java Peristance API book, page 237. Pro EJB 3 Java Peristance API书籍第237页中有一些示例。

Could you make a database view and then create an entity that maps onto that view? 您能否制作一个数据库视图,然后创建一个映射到该视图的实体? I don't know if this is possible, just a thought. 我不知道这是否可行,只是一个想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM