JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Object Relational Mapping » Hibernate  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 如何控制spring+hibernate的数据库连接
unser





發文: 26
積分: 0
於 2006-04-04 14:13 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
spring.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
 
<beans>
 
  <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" destroy-method="close">
    <property name="driverClassName">
      <value>com.mysql.jdbc.Driver</value>
    </property>
    <property name="url">
      <value>jdbc:mysql://localhost:3306/yy?useUnicode=true&characterEncoding=GBK&autoReconnect=true</value>
    </property>
    <property name="username">
      <value>root</value>
    </property>
    <property name="password">
      <value>123456</value>
    </property>
  </bean>
 
  <!-- Hibernate -->
  <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
      <ref bean="dataSource" />
    </property>
    <property name="hibernateProperties">
      <props>
        <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
        <prop key="hibernate.show_sql">false</prop>
        <prop key="hibernate.c3p0.minPoolSize">5</prop>
        <prop key="hibernate.c3p0.maxPoolSize">20</prop>
        <prop key="hibernate.c3p0.timeout">100</prop>
        <prop key="hibernate.c3p0.max_statement">50</prop>
        <prop key="hibernate.c3p0.testConnectionOnCheckout">false</prop>
        <prop key="hibernate.max_fetch_depth">3</prop>
      </props>
    </property>
    <property name="mappingResources">
      <list>
        <value>cn/soyu/sender/mail/views/Sendmail.hbm.xml</value>
      </list>
    </property>
  </bean>
 
  <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory">
      <ref local="sessionFactory" />
    </property>
  </bean>
 
  <!--  -->
  <bean id="mailDAO" class="cn.soyu.sender.mail.Hibernate.MailWithDAOHibernateImpl">
    <property name="sessionFactory">
      <ref local="sessionFactory" />
    </property>
  </bean>
 
  <bean id="mailDAOProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="transactionManager">
      <ref bean="transactionManager" />
    </property>
    <property name="target">
      <ref local="mailDAO" />
    </property>
    <property name="transactionAttributes">
      <props>
        <prop key="insert*">PROPAGATION_REQUIRED</prop>
        <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
        <prop key="is*">PROPAGATION_REQUIRED,readOnly</prop>
      </props>
    </property>
  </bean>
 
</beans>


初始化方法
1
2
ApplicationContext context =  new FileSystemXmlApplicationContext("spring.xml");
MailDAO mailDAO = (MailDAO)context.getBean("mailDAOProxy")


因为我是开10条线程一起处理的,但数据库过万时,它就出现以下的错误:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
- SQL Error: 0, SQLState: 08001
- Server connection failure during transaction. Due to underlying exception: 'java.net.BindException: Address already in use: connect'.
 
** BEGIN NESTED EXCEPTION ** 
 
java.net.BindException
MESSAGE: Address already in use: connect
 
STACKTRACE:
 
java.net.BindException: Address already in use: connect
  at java.net.PlainSocketImpl.socketConnect(Native Method)
  at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
  at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
  at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
  at java.net.Socket.connect(Socket.java:452)
  at java.net.Socket.connect(Socket.java:402)
  at java.net.Socket.<init>(Socket.java:309)
  at java.net.Socket.<init>(Socket.java:124)
  at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:124)
  at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:225)
  at com.mysql.jdbc.Connection.createNewIO(Connection.java:1895)
  at com.mysql.jdbc.Connection.<init>(Connection.java:450)
  at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411)
  at java.sql.DriverManager.getConnection(DriverManager.java:512)
  at java.sql.DriverManager.getConnection(DriverManager.java:140)
  at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:290)
  at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:276)
  at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:258)
  at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:240)
  at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:80)
  at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:298)
  at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:110)
  at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:76)
  at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:69)
  at org.hibernate.hql.ast.UpdateStatementExecutor.execute(UpdateStatementExecutor.java:63)
  at org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:297)
  at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:871)
  at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:89)
  at cn.soyu.sender.mail.Hibernate.MailWithDAOHibernateImpl.setMailStatus(MailWithDAOHibernateImpl.java:68)
  at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  at java.lang.reflect.Method.invoke(Method.java:324)
  at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:292)
  at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:163)
  at $Proxy1.setMailStatus(Unknown Source)
  at cn.soyu.sender.mail.SendMailHelper.setMailStatus(SendMailHelper.java:98)
  at cn.soyu.sender.mail.SendMailTask.run(SendMailTask.java:96)
  at java.lang.Thread.run(Thread.java:534)
 
** END NESTED EXCEPTION **
 
Attempted reconnect 3 times. Giving up.


reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
3086 如何控制spring+hibernate的数据库连接 unser 6109 2006-04-04 14:13
2522 Re:如何控制spring+hibernate的数据库连接 unser 11 2006-04-04 14:45
2417 Re:如何控制spring+hibernate的数据库连接 koji 134 2006-04-10 11:29
2211 Re:如何控制spring+hibernate的数据库连接 joy6811 58 2006-06-28 15:41
2234 Re:如何控制spring+hibernate的数据库连接 unser 53 2006-06-29 21:50
2120 Re:如何控制spring+hibernate的数据库连接 joy6811 112 2006-08-17 14:07
» JWorld@TW »  Object Relational Mapping » Hibernate

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8