当我有非常简单的域模型(3个表没有任何关系)时,我所有的实体都没有实现Serializable。 p>
但是当域模型变得更加复杂时,我得到了RuntimeException,它说我的一个实体没有实现Serializable.B $ b
我使用Hibernate作为JPA实现。
我想知道:
解决方案
如果您混合使用HQL和原生SQL查询,通常会发生这种情况。在HQL中,Hibernate将您传递的类型映射到数据库理解的任何内容。当你运行本地SQL时,你必须自己做映射。如果你不这样做,那么默认的映射就是序列化参数并将其发送到数据库(希望它理解它)。
The question is in the title. Below I just described some of my thoughts and findings.
When I had very simple domain model (3 tables without any relations) all my entities did NOT implement Serializable.
But when domain model became more complex I got RuntimeException which said that one of my entities didn't implement Serializable.
I use Hibernate as a JPA implementation.
I wonder:
解决方案
This usually happens if you mix HQL and native SQL queries. In HQL, Hibernate maps the types you pass in to whatever the DB understands. When you run native SQL, then you must do the mapping yourself. If you don't, then the default mapping is to serialize the parameter and send it to the database (in the hope that it does understand it).
更多推荐
何时以及为什么JPA实体应该实现Serializable接口?
发布评论