Why Quarkus-Hibernate is looking for Persistance.xml when we have already given @DataSource?

huangapple go评论61阅读模式
英文:

Why Quarkus-Hibernate is looking for Persistance.xml when we have already given @DataSource?

问题

我正在尝试构建 Hibernate 项目,并在以下位置指定了属性:

cron.expr=* 12 15 * * ?

quarkus.datasource.driver=oracle.jdbc.driver.OracleDriver
quarkus.hibernate-orm.dialect=oracle.jdbc.driver.OracleDriver
quarkus.datasource.ergo.url=jdbc:oracle:thin:@myhost:1521:orcl
quarkus.datasource.ergo.driver=oracle.jdbc.driver.OracleDriver
quarkus.datasource.ergo.username=quarkus_test
quarkus.datasource.ergo.password=quarkus_test

quarkus.datasource.mds.url=jdbc:oracle:thin:@myhost:1521:orcl
quarkus.datasource.mds.driver=oracle.jdbc.driver.OracleDriver
quarkus.datasource.mds.username=quarkus_test
quarkus.datasource.mds.password=quarkus_test

运行后,会在信息中显示以下消息:

HHH000318: Could not find any META-INF/persistence.xml file in the classpath

我应该在 persistence.xml 中写什么?Quarkus 的 persistence.xml 应该是什么样的?在 Java 类中使用 @Datasource 注解时,是否真的需要它?

以下是在之前部署在 Wildfly 中的项目中的 persistence.xml:

<persistence version="2.1"
             xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">

    <persistence-unit name="ePU" transaction-type="JTA">
        <jta-data-source>java:/datasources/EDS</jta-data-source>
    </persistence-unit>
	
    <persistence-unit name="mPU" transaction-type="JTA">
        <jta-data-source>java:/datasources/MDS</jta-data-source>
    </persistence-unit>
    
</persistence>

希望这些信息对你有所帮助。

英文:

I am trying to build hibernate project and i have mentioned properties in

cron.expr=* 12 15 * * ?

quarkus.datasource.driver=oracle.jdbc.driver.OracleDriver
quarkus.hibernate-orm.dialect=oracle.jdbc.driver.OracleDriver
quarkus.datasource.ergo.url=jdbc:oracle:thin:@myhost:1521:orcl
quarkus.datasource.ergo.driver=oracle.jdbc.driver.OracleDriver
quarkus.datasource.ergo.username=quarkus_test
quarkus.datasource.ergo.password=quarkus_test

quarkus.datasource.mds.url=jdbc:oracle:thin:@myhost:1521:orcl
quarkus.datasource.mds.driver=oracle.jdbc.driver.OracleDriver
quarkus.datasource.mds.username=quarkus_test
quarkus.datasource.mds.password=quarkus_test

After running it is giving following message in info:

HHH000318: Could not find any META-INF/persistence.xml file in the classpath

What shall i write in persistance.xml? How quakus persistance.xml will look like? Is it really required when we are giving @Datasource annotation within java class

Following is persistance.xml in previous project deployed in wildfly:

&lt;persistence version=&quot;2.1&quot;
             xmlns=&quot;http://xmlns.jcp.org/xml/ns/persistence&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
             xsi:schemaLocation=&quot;http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd&quot;&gt;

    &lt;persistence-unit name=&quot;ePU&quot; transaction-type=&quot;JTA&quot;&gt;
        &lt;jta-data-source&gt;java:/datasources/EDS&lt;/jta-data-source&gt;
    &lt;/persistence-unit&gt;
	
    &lt;persistence-unit name=&quot;mPU&quot; transaction-type=&quot;JTA&quot;&gt;
        &lt;jta-data-source&gt;java:/datasources/MDS&lt;/jta-data-source&gt;
    &lt;/persistence-unit&gt;
    
&lt;/persistence&gt;

答案1

得分: 1

persistence.xml 是可选的,这只是Hibernate发出的一个INFO消息,您可以放心忽略。

Quarkus在构建时启动Hibernate,无需persistence.xml文件,如果您想要扩展配置,可以添加它,但在大多数情况下是不必要的。

英文:

persistence.xml is optional, this is just an INFO message from Hibernate that you can safely ignore.

Quarkus bootstrap Hibernate at build time without the need to a persistence.xml file, you can add it if you want for extended configuration but in most cases this is not needed.

huangapple
  • 本文由 发表于 2020年1月3日 18:57:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/59577339.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定