为了账号安全,请及时绑定邮箱和手机立即绑定

我是否需要Persistence.xml中的<class>元素?

我是否需要Persistence.xml中的<class>元素?

GCT1015 2019-12-18 17:13:45
我是否需要Persistence.xml中的<class>元素?我有一个非常简单的sistance.xml文件:<?xml version="1.0" encoding="UTF-8"?><persistence version="1.0"     xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">     <persistence-unit name="eventractor" transaction-type="RESOURCE_LOCAL">         <class>pl.michalmech.eventractor.domain.User</class>         <class>pl.michalmech.eventractor.domain.Address</class>         <class>pl.michalmech.eventractor.domain.City</class>         <class>pl.michalmech.eventractor.domain.Country</class>         <properties>             <property name="hibernate.hbm2ddl.auto" value="validate" />             <property name="hibernate.show_sql" value="true" />         </properties>     </persistence-unit></persistence>而且起作用了。但当我移除<class>元素应用程序看不到实体(所有类都用@Entity).有没有自动扫描机制@Entity上课?
查看完整描述

3 回答

?
慕哥6287543

TA贡献1831条经验 获得超10个赞

对于那些在Spring中运行JPA的人,从3.1版开始,您可以设置packagesToScan财产LocalContainerEntityManagerFactoryBean并且完全摆脱了sistence.xml。

这是低层的


查看完整回答
反对 回复 2019-12-19
  • 3 回答
  • 0 关注
  • 427 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信