2012-09-16 11 views
9

Wdrażamy aplikację internetową przy użyciu JPA2.0 i Hibernate3.0. Konfiguracje pul połączeń konfiguruje się w pliku persistence.xml znajdującym się w folderze META-INF.Konfiguracje C3P0! Gdzie i jak?


persistence.xml:

<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0"> 
    <persistence-unit name="MyPU" transaction-type="RESOURCE_LOCAL"> 
     <!-- Entity Classes--> 
     <properties> 
      <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/> 
      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/> 
      <property name="hibernate.show_sql" value="true"/> 
      <property name="bytecode.provider" value="org.hibernate.bytecode.javassist.BytecodeProviderImpl"/> 
      <property name="hibernate.connection.username" value="{username}"/> 
      <property name="hibernate.connection.password" value="{password}"/> 
      <property name="hibernate.hbm2ddl.auto" value="update"/> 
      <property name="hibernate.format_sql" value="true"/> 
      <property name="hibernate.connection.url" value="{jdbc url}"/> 

      <property name="hibernate.c3p0.min_size" value="1"/> 
      <property name="hibernate.c3p0.timeout" value="1000"/> 
      <property name="hibernate.c3p0.acquire_increment" value="1"/> 
      <property name="hibernate.c3p0.idle_test_periods" value="600"/> 
      <property name="hibernate.c3p0.testConnectionOnCheckin" value="true"/> 
      <property name="hibernate.c3p0.preferredTestQuery" value="SELECT 1;"/> 
     </properties> 
    </persistence-unit> 
</persistence> 

Mamy problem z konfiguracji puli połączeń. Wygląda na to, że konfiguracje nie mają żadnego efektu, a połączenie zostanie przerwane po 8 godzinach. Czy potrzebujemy innego pliku konfiguracyjnego, takiego jak hibernate.cfg.xml czy hibernate.properties?

Każda pomoc jest mile widziane.

Odpowiedz

4

Miałem ten sam problem z właściwościami, które umieściłem w persistence.xml nie wpłynęło na c3p0.

Patrząc na http://www.mchange.com/projects/c3p0/index.html#configuration_files Próbowałem umieścić plik xml o nazwie c3p0-config.xml i umieścić go w WEB-INF/classes i działa idealnie.

Oto przykład pliku c3p0-config.xml:

<c3p0-config> 
    <default-config> 
    <property name="automaticTestTable">con_test</property> 
    <property name="checkoutTimeout">30000</property> 
    <property name="idleConnectionTestPeriod">30</property> 
    <property name="initialPoolSize">10</property> 
    <property name="maxIdleTime">30</property> 
    <property name="maxPoolSize">100</property> 
    <property name="minPoolSize">10</property> 
    <property name="maxStatements">200</property> 

    <user-overrides user="test-user"> 
     <property name="maxPoolSize">10</property> 
     <property name="minPoolSize">1</property> 
     <property name="maxStatements">0</property> 
    </user-overrides> 

    </default-config> 
</c3p0-config> 
+0

Philipi Willemann ma rację, jeśli dodasz xml config c3p0, właściwości zostaną odczytane poprawnie. N.B. jeśli dodasz pewne właściwości konfiguracji, które są już opisane w pliku hibernate.config, hibernacja zignoruje je. Więcej informacji można znaleźć tutaj: http://www.mchange.com/projects/c3p0/index.html#configuration_files w sekcji "Przesłanianie domyślnych ustawień c3p0 za pośrednictwem c3p0-config.xml" – sataniccrow

1

miałem dokładnie taki sam problem, moim problemem było to, że mój zbiornik aplikacji internetowych (Tomcat) kierował moje połączenia z bazą danych. Musiałem przenieść konfigurację c3p0 z mojego pliku persistence.xml do context.xml Tomcat. Podany link Domenic D jest świetnym miejscem do rozpoczęcia, jeśli to twój problem.

Powiązane problemy