关于hibernate配置和SAE MYSQL的问题

J2EE 码拜 9年前 (2015-04-15) 931次浏览 0个评论

最近小弟想使用JAVA开发一个微信公众平台,于是租用了SAE的服务器
在和数据库交互的过程中不知道哪里出了问题,
由于不太会用hibernate所以也不知道是连接SAE上出了问题还是配置或者mapping的时候写错了。。求大神指点
下面是hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
		"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
		"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.password">xxxxxxxxxxxxxxxx</property>
        <property name="hibernate.connection.url">jdbc:mysql://w.rdc.sae.sina.com.cn:3307/app_appname</property>
        <property name="hibernate.connection.username">xxxxxxxxxxxxxx</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
        <mapping resource = "/mapping/NewMapping.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

其中password和username都是从SAE应用管理上面粘下来的,是一堆乱七八糟的东西
appname就是app的名字

下面是newmapping.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
	"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
	"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package = "ermengmeng.wxqueue">

  <class name="Business" table = "bus">
  <id name = "No"></id>
  <property name = "name"/>
  </class>
</hibernate-mapping>

下面是在doPost中的代码。。。

        	Configuration conf = new Configuration().configure();
        	ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(conf.getProperties()).build();
        	SessionFactory sf = conf.buildSessionFactory(serviceRegistry);
        	Session sess = sf.openSession();
        	Transaction tx = sess.beginTransaction();
        	Business b = new Business(10,"111");
        	sess.save(b);
        	tx.commit();
        	sess.close();
        	sf.close();

感觉应该对数据库可以操作了才对。。。是不是我还漏掉了什么。。或者什么地方写的不对。。。求各位大神指教。。

关于hibernate配置和SAE MYSQL的问题
问题解决了。。。
是我没提供全set/get方法。。。
关于hibernate配置和SAE MYSQL的问题
100分
楼主真的是太聪明啦!膜拜Java大神
关于hibernate配置和SAE MYSQL的问题
楼主提供的代码很值得学习!
关于hibernate配置和SAE MYSQL的问题
用户名是不是SAE_MYSQL_USER这个?

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明关于hibernate配置和SAE MYSQL的问题
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!