English 中文(简体)
可以/应当利用日本邮政局来回价值而不是实体?
原标题:Can/should JPA be used to return values rather than entities?
  • 时间:2009-11-17 19:18:38
  •  标签:
  • java
  • jpa
  • jdbc

我会利用日本财团开展一个项目,而且在大多数情况下,都希望获得实体,但有一些案例(报告是其中之一,但还有其他一些)我不想或需要获得实体,而是希望选择价值观。 JPA是否支持这一点? 如果是的话,使用它是否有意义,或者在这些情况下使用直线的亚行是否有意义?

最佳回答

Q1: Yes, it does.

它提出了所谓的cal问题,例如:

select u.name from User u 

而不是

select u from User u

Q2: When it comes to sense of using it: Such queries have sense - you just simply need a single property not the whole object. But if you plan to make all your queries only fetching separate values, then the question why? seems valid. The whole idea of O/R mappers is to allow you operate on objects, not (related) tables and ids. So fetching ids using JPA usually doesn t make sense. Once you have objects mapped to database, it should be easier for you to operate on the data.

问题回答

SQLResultsetMappingWithAlias at java2s.com,似乎就你所期待的情况提供了一个实例。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签