当前位置: 首页 > 知识库问答 >
问题:

在服务器启动时跳过持久性单元验证

相旭
2023-03-14
<?xml version="1.0" encoding="UTF-8" ?>
<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_2_0.xsd"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="ec2Production" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
    <properties>
        <property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider" />
        <property name="hibernate.show_sql" value="false" />
        <property name="hibernate.format_sql" value="false" />

        <property name="hibernate.connection.driver_class"  value="com.mysql.jdbc.Driver" />
        <property name="hibernate.connection.url" value="jdbc:mysql://xxxxx:3306/xxxxx?autoReconnect=true" />
        <property name="hibernate.connection.username" value="xxxxxx" />
        <property name="hibernate.connection.password" value="xxxxx" />

        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
        <property name="hibernate.c3p0.acquire_increment" value="1"/>
        <property name="hibernate.c3p0.max_size" value="15"/>
        <!-- it must be set to LESS than the wait_timout setting for the mysql server (this setting defaults to 28800 secs (8 hours)) -->
        <property name="hibernate.c3p0.idle_test_period" value="28680" />
        <property name="hibernate.c3p0.preferredTestQuery" value="select 1;" />
        <property name="hibernate.c3p0.timeout" value="60000"/>
        <property name="hibernate.connection.zeroDateTimeBehavior" value="convertToNull"/>
        <property name="hibernate.c3p0.debugUnreturnedConnectionStackTraces " value="true"/>
        <property name="debugUnreturnedConnectionStackTraces " value="true"/>
        <property name="hibernate.cache.use_second_level_cache" value="true" />
        <property name="hibernate.cache.use_query_cache" value="true" />
        <property name="hibernate.cache.region.factory_class" value="com.mc.hibernate.memcached.MemcachedRegionFactory" />
        <property name="hibernate.memcached.operationTimeout" value = "40000"/>
        <property name="hibernate.memcached.connectionFactory" value = "KetamaConnectionFactory"/>
        <property name="hibernate.memcached.hashAlgorithm" value = "HashAlgorithm.FNV1_64_HASH"/>
        <property name="hibernate.memcached.servers" value = "xxxxxxxxxx:11211"/>

        <property name="hibernate.cache.region_prefix" value=""/>
    </properties>
</persistence-unit>

<persistence-unit name="ec2Marketing" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
    <properties>
        <property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider" />
        <property name="hibernate.show_sql" value="false" />
        <property name="hibernate.format_sql" value="false" />

        <property name="hibernate.connection.driver_class"  value="com.mysql.jdbc.Driver" />
        <property name="hibernate.connection.url" value="jdbc:mysql://xxxxxx:3306/xxxxxx?autoReconnect=true" />
        <property name="hibernate.connection.username" value="xxxxx" />
        <property name="hibernate.connection.password" value="xxxxxxx" />

        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
        <property name="hibernate.c3p0.acquire_increment" value="1"/>
        <property name="hibernate.c3p0.max_size" value="40"/>
        <property name="hibernate.c3p0.idle_test_period" value="28680" />
        <property name="hibernate.c3p0.preferredTestQuery" value="select 1;" />
        <property name="hibernate.c3p0.timeout" value="60000"/>
        <property name="hibernate.connection.zeroDateTimeBehavior" value="convertToNull"/>
        <property name="hibernate.c3p0.debugUnreturnedConnectionStackTraces " value="true"/>
        <property name="debugUnreturnedConnectionStackTraces " value="true"/>
        <property name="hibernate.cache.use_second_level_cache" value="true" />
        <property name="hibernate.cache.use_query_cache" value="true" />
        <property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory" />
        <property name="hibernate.cache.region.factory_class" value="com.mc.hibernate.memcached.MemcachedRegionFactory" />
        <property name="hibernate.memcached.operationTimeout" value = "40000"/>
        <property name="hibernate.memcached.connectionFactory" value = "KetamaConnectionFactory"/>
        <property name="hibernate.memcached.hashAlgorithm" value = "HashAlgorithm.FNV1_64_HASH"/>
        <property name="hibernate.memcached.servers" value = "xxxxxx:11211"/>

        <property name="hibernate.cache.region_prefix" value=""/>
    </properties>
</persistence-unit>

共有1个答案

羿博延
2023-03-14
<Resource id="jdbc/moviesdb" type="DataSource">
  JdbcDriver=com.mysql.jdbc.Driver
  JdbcUrl=jdbc:mysql:localhost:3306/moviesdb
  UserName=sa
  Password=secret
  JtaManaged=true
  ValidationQuery=SELECT 1
  TestOnBorrow=true
</Resource>
   <property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider" />
        <property name="hibernate.show_sql" value="false" />
        <property name="hibernate.format_sql" value="false" />

        <property name="hibernate.connection.driver_class"  value="com.mysql.jdbc.Driver" />
        <property name="hibernate.connection.url" value="jdbc:mysql://xxxxx:3306/xxxxx?autoReconnect=true" />
        <property name="hibernate.connection.username" value="xxxxxx" />
        <property name="hibernate.connection.password" value="xxxxx" />

        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
        <property name="hibernate.c3p0.acquire_increment" value="1"/>
        <property name="hibernate.c3p0.max_size" value="15"/>
        <!-- it must be set to LESS than the wait_timout setting for the mysql server (this setting defaults to 28800 secs (8 hours)) -->
        <property name="hibernate.c3p0.idle_test_period" value="28680" />
        <property name="hibernate.c3p0.preferredTestQuery" value="select 1;" />
        <property name="hibernate.c3p0.timeout" value="60000"/>
        <property name="hibernate.connection.zeroDateTimeBehavior" value="convertToNull"/>
        <property name="hibernate.c3p0.debugUnreturnedConnectionStackTraces " value="true"/>
        <property name="debugUnreturnedConnectionStackTraces " value="true"/>
<jta-data-source>jdbc/moviesdb</jta-data-source>
 类似资料:
  • 我正在使用Eclipse和WildFly11开发一个基于maven的JSF+JPA+EJB3.2项目。启动应用程序服务器时,我收到以下错误: 我正在无状态bean中注入EntityManager: 为什么容器找不到persistence.xml文件?persistence.xml存在于META-INF目录中。如有任何帮助,我们将不胜感激。多谢了。 更新:这里是项目目录结构,persistence.

  • 问题内容: 我有一个Express 4应用程序设置来进行会话。 当我提交表单时,它将user_id保存到req.session中。但是,当我重新启动服务器时,会话消失了。 为什么不持续?我是否缺少某些配置? 问题答案: express-session的默认会话存储是MemoryStore,顾名思义,该存储仅将会话存储在内存中。如果需要持久性,则有许多可用于Express的会话存储。一些例子: co

  • 问题内容: 在构建应用程序时会创建persistence.xml中的持久性单元。由于我想在运行时更改数据库URL,是否有任何方法可以在运行时修改持久性单元?我应该使用其他数据库,而不是在分发后预先绑定一个数据库。 我正在使用EclipseLink(JPA 2.1) 问题答案: 保持持久性单元文件(Persistence.xml)不变。您可以按如下所示覆盖其中的属性。

  • 我能知道Hazelcast支持磁盘持久性吗?换句话说,我可以使用Hazelcast作为常规数据库吗?(就像apache点火一样)。

  • Hibernate被设置为pom.xml中的依赖项: 当我们在Wildfly8和9上时,这些依赖关系运行良好。想知道我可能在配置中遗漏了什么?

  • 我正在编写一个独立的java应用程序,从Maven项目构建它并通过调用jar文件执行。 在应用程序中,我有一个实体管理器,它使用在我的持久性中定义的持久性单元。xml是独立的(事务类型=“RESOURCE\u LOCAL”) 实际的实体注释类来自另一个项目,因此被添加到pom中。xml文件作为依赖项。 问题是持久性。包含实体类的项目的xml覆盖了实际独立应用程序的持久性。构建jar时,jar目标文