Java版 - Questions on EJB3 Persistence/Hibernate |
|
|
|
|
|
T*****e 发帖数: 361 | 1 I am using EJB3 Persistence through Hibernate. My entity classes are
annotated and packed in a jar file. It works.
I have two questions.
The first one is quite simple. Can I use simple classes (other than
entities) in EJB/QL? Example:
List addresses = entityManager.createNativeQuery(
"select u.address from user as u").listResults();
The above query seems fine. But how can I use the result? I've tried:
String address = (String) addresses.get(i);
but it doesnot' work.
The second questio | T*****e 发帖数: 361 | 2 呵呵,每人理我,只好自己顶一下。
对于第二个问题:
最初我发帖的时候,并未从google上找到有用的信息。今天把
Hiberbate的源代码找出来看了看,发现Hibernate居然试图
把我定义的Map转换为java.sql.Blob,这
才导致了Exception。看上去更像Hibernate的问题,而不是
我自己的。
重新上google找了找,还真有人提到这个问题,说是Hibernate
的@Lob不支持Map interface,因为从interface本身不能判
断出是否Serializable。也有道理,不过也太不方便了。
刚才把我的Map都替换成HashMap
String>,试了一下,果然就没有问题了。
嗯,Open Source的一个好处就是,实在没有办法的时候,总
还可以指望有代码可以看看。上次用TrueZip的一个函数来实
现Zip Entry的直接读写(没有解压、压缩),让Supervisor
很是满意,算是挣了点credit。
那天有空再折腾一下第一个问题,搞明白之后再回来汇报一下。
【在 T*****e 的大作中提到】 : I am using EJB3 Persistence through Hibernate. My entity classes are : annotated and packed in a jar file. It works. : I have two questions. : The first one is quite simple. Can I use simple classes (other than : entities) in EJB/QL? Example: : List addresses = entityManager.createNativeQuery( : "select u.address from user as u").listResults(); : The above query seems fine. But how can I use the result? I've tried: : String address = (String) addresses.get(i); : but it doesnot' work.
|
|
|
|
|
|