In Spring Data JPA, How to add an Entity during ru

2019-08-16 09:06发布

In my business, I will to dynamically create model and repository for MySQL. I have successfully create the java file and complied it. then register the bean for repository and service using beanfactory. But I don't have an idea about how to map the Entity. I have searched some similar questions but do not have a clean solution. can anyone help and show me some code samples ?

1条回答
Animai°情兽
2楼-- · 2019-08-16 09:52

JPA works mostly with static schema. There are good reasons for this, see discussion on www.java.net/node/666078 .

I know only about 3 solutions:

1) refactor/ change your domain model to be static ( best way but there are some real world situations where you really need at least 1 or 2 dynamic tables)

2) use native queries and @SqlResultSetMapping for dynamic tables ( this is solution I am using in such special cases)

3) use Jpa provider non portable specific ways ( in fact not JPA) see for example http://www.infoq.com/articles/hibernate-custom-fields

查看更多
登录 后发表回答