请教问题,求指点

请教问题如下:

(下面是进行的双向的多对多的关联关系进行拆分的测试,拆分成两个多对一的关联,但是没有成功的一步就是:只是生成了两张表,还有一张ORDER表没有生成,请教原因还修改的方式,谢了)

【POJO类】

package qau.edu.ren;

import java.util.Date;

import java.util.HashSet;

import java.util.Set;

public class Order {

private int id ;

private Date date ;

private String name ;

private Set<Op> ops = new HashSet<Op>();

public int getId() {

return id;

}

public void setId(int id) {

this.id = id;

}

public Date getDate() {

return date;

}

public void setDate(Date date) {

this.date = date;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public Set<Op> getOps() {

return ops;

}

public void setOps(Set<Op> ops) {

this.ops = ops;

}

}

———————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

package qau.edu.ren;

import java.util.Date;

import java.util.HashSet;

import java.util.Set;

public class Product {

private int id ;

private String name ;

private Date date ;

private Set<Op> op = new HashSet<Op>();

public int getId() {

return id;

}

public void setId(int id) {

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public Date getDate() {

return date;

}

public void setDate(Date date) {

this.date = date;

}

public Set<Op> getOp() {

return op;

}

public void setOp(Set<Op> op) {

this.op = op;

}

}

——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

package qau.edu.ren;

import java.util.Date;

public class Op {

private int id ;

private double price ;

private Date date ;

private Order orders ;

private Product pros ;

public int getId() {

return id;

}

public void setId(int id) {

this.id = id;

}

public double getPrice() {

return price;

}

public void setPrice(double price) {

this.price = price;

}

public Date getDate() {

return date;

}

public void setDate(Date date) {

this.date = date;

}

public Order getOrders() {

return orders;

}

public void setOrders(Order orders) {

this.orders = orders;

}

public Product getPros() {

return pros;

}

public void setPros(Product pros) {

this.pros = pros;

}

}

———————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

【关系映射文件】

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"

"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<!-- Generated 2014-11-12 20:48:07 by Hibernate Tools 3.4.0.CR1 -->

<hibernate-mapping>

<class name="qau.edu.ren.Op" table="OP">

<id name="id" type="int">

<column name="OP_ID" />

<generator class="native" />

</id>

<property name="price" type="double">

<column name="OP_PRICE" />

</property>

<property name="date" type="java.util.Date">

<column name="OP_DATE" />

</property>

<many-to-one name="orders" class="qau.edu.ren.Order" fetch="join">

<column name="O_ID" />

</many-to-one>

<many-to-one name="pros" class="qau.edu.ren.Product" fetch="join">

<column name="P_ID" />

</many-to-one>

</class>

</hibernate-mapping>

***********************************************************************************************************************************************************************************************************************************************

<?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>

<class name="qau.edu.ren.Order" table="ORDER">

<id name="id" type="int">

<column name="O_ID" />

<generator class="native" />

</id>

<property name="date" type="java.util.Date">

<column name="O_DATE" />

</property>

<property name="name" type="java.lang.String">

<column name="O_NAME" />

</property>

<set name="ops" table="OP" inverse="true">

<key>

<column name="O_ID"/>

</key>

<one-to-many class="qau.edu.ren.Op" />

</set>

</class>

</hibernate-mapping>

***********************************************************************************************************************************************************************************************************************************************

<?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>

<class name="qau.edu.ren.Product" table="PRODUCT">

<id name="id" type="int">

<column name="P_ID" />

<generator class="native" />

</id>

<property name="name" type="java.lang.String">

<column name="P_NAME" />

</property>

<property name="date" type="java.util.Date">

<column name="P_DATE" />

</property>

<set name="op" table="OP" inverse="true">

<key>

<column name="P_ID" />

</key>

<one-to-many class="qau.edu.ren.Op" />

</set>

</class>

</hibernate-mapping>

************************************************************************************************************************************************************************************************************************************************

【配置文件】

<?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">123456</property>

<property name="hibernate.connection.url">jdbc:mysql:///test</property>

<property name="hibernate.connection.username">root</property>

<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>

<!-- 配置数据表的生成方式 -->

<property name="hbm2ddl.auto">update</property>

<!-- 配置SQL输出的格式 -->

<property name="show_sql">true</property>

<property name="format_sql">true</property>

<!-- 配置关系映射文件的加载路径 -->

<mapping resource="qau/edu/ren/Product.hbm.xml" />

<mapping resource="qau/edu/ren/Op.hbm.xml" />

<mapping resource="qau/edu/ren/Order.hbm.xml" />

<!-- <mapping resource="qau/edu/jian/Person.hbm.xml"/> -->

</session-factory>

</hibernate-configuration>

************************************************************************************************************************************************************************************************************************************************

【测试类】

package qau.edu.ren;

import java.util.Date;

import org.hibernate.Session;

import org.hibernate.Transaction;

import org.hibernate.cfg.Configuration;

public class Test {

public static void main(String[] args) {

Session session = new Configuration().configure().buildSessionFactory()

.openSession();

Transaction tr = session.beginTransaction();

Order or = new Order();

or.setDate(new Date());

or.setName("AA");

Product pro = new Product();

pro.setDate(new Date());

pro.setName("BB");

Op op = new Op();

op.setDate(new Date());

op.setPrice(2232.22);

or.getOps().add(op);

pro.getOp().add(op);

session.save(pro);

session.save(or);

session.save(op);

tr.commit();

session.close();

}

}

【出现的错误:】

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Hibernate:
insert
into
PRODUCT
(P_NAME, P_DATE)
values
(?, ?)
Hibernate:
insert
into

ORDER (O_DATE
, O_NAME)
values
(?, ?)
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not insert: [qau.edu.ren.Order]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:64)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2329)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2836)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:268)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:321)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:705)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:693)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:689)
at qau.edu.ren.Test.main(Test.java:39)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘ORDER (O_DATE, O_NAME) values (‘2014-11-12 22:30:17.0‘, ‘AA‘)‘ at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3558)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3490)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2109)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2648)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2077)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2362)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2280)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2265)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:94)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:57)
... 16 more

时间: 2024-10-26 20:29:03

请教问题,求指点的相关文章

服务器正式环境性能测试nginx-php 求指点性能提升突破口

由于本人身处第三级城市.无法接触到比较牛逼的公司或者环境,以下正是网站环境摸了度娘好几遍,搭建完成,测试下已寻求提升空间.也希望自己能配置出能满足公司需要的网站运行环境,不能因为我这边的瓶颈而阻碍了公司进行,希望各位大能能不吝惜指点下谢谢. 1.阿里云云服务器ecs配置如下4核8G内存 10M带宽 2.php运行环境 Tengine-2.0.3  +php-fpm*4 一个nginx主进程 一个server主站 5个php-fpm进程 (4个负载均衡 1个备用) 3.程序优化 js/css 压缩

关于缓存 (这个自己也在慢慢学习,慢慢总结中,有路过的,求指点,赶紧不尽。。。)

主要有两种方式: 1.建立一个全局HashMap静态变量,适合缓存数据较少的情况: public HashMap<String, CouponsInfo> couponMap = new HashMap<String, CouponsInfo>(); //在Application中为缓存所需的couponMap初始化 baseApplication.couponMap.put(coupons.getCouponID()+"", coupons);//缓存操作 /

线程同步的诡异:求指点

public class BUYER { public static void main(String[] args) {   TestThread a=new TestThread();   TestThread B=new TestThread();  a.setName("A");  B.setName("B");  a.start();    B.start(); }}class TestThread extends Thread{ static int R

Qt 中碰到的一些错误 求指点

刚刚学Qt,碰到的错误也不是很多 1. 包含了<QtGui>后,编译的时候仍报错,说有很多控件的头文件找不到. 解决方法:  我用的qt版本是5.x.据说qt4的时候,控件的头文件定义都集成在QtGui中.但是在qt5中,是集成在<QtWidgets>中的.直接包含它就好. 如果再不行,可能就是加载不到控件,可以在.pro文件中加入 "QT += widgets" 2. 信号有传递参数的作用,只用声明,不用实现.否则会报错.因为moc规则生成了相关的代码,你自己

我所不理解的命令,求指点

hist(w)   ?  是绘制函数吗? save hello v; save hello.txt v -ascii; load hello.dat load hello.txt   以上一组代码没能实现? log(v) ?  可以理解是取对数吗? exp(v)   ? find(a < 3)  ? A = magic(3) ? [r,c] = find(A>=7) ? prod(a)   ?可以理解是取最大值吗?   val = max(a) 实现的不是最大值的功能吗? 两者的不同? flo

“找女神要QQ号码”——跟风篇java新手版(求指点)

吃完粽子后闲来无事,于是准备在园子里面看看.突然看到了一个“找女神要QQ号码”的文章,顿时精力充沛了~~^_^. 该文章楼主说明此算法来自于<啊哈!算法>,图文并茂,非常不错.<啊哈!算法>.pdf下载地址:http://vdisk.weibo.com/s/zzBPqzw3MPnbM 本来只是看看而已,结果发现评论很火爆,都在发自己的实现代码. 比如:美女程序员是如何将QQ转换成题目中那串数字的--读博文<找女神要QQ号码> http://www.cnblogs.com

编了个21点游戏 结果错误好多的样子T T求指点

#include<stdio.h>#include<stdlib.h>#include<string.h>int n1=2,n2=2;int main(){    void Game();    char str[10];    printf("if you want to start the game,enter start,otherwise log out\n");    gets(str);    if(strcmp(str,"st

OJ题目:字符串匹配求指点

kogioi奖凰豢形慌材<http://weibo.com/20180414p/230927983085792249257984> iiauua俳炕案沼芬喂<http://weibo.com/p978p478p/230927983067083371712512> o6skc2暇任撂啦乘闻<http://weibo.com/p20180414p/230927983037668214444032?z1> qscm8c呛颇佑烁橇狼<http://weibo.com/kq

刚性微分方程与非刚性的大概区分(自看,求指点)

(这里的内容是作为自己的一个粗略的总结,不确定是否正确,希望有大佬能够更明确的指出其中的错误,作出指导) 对于刚性和非刚性微分方程的区分,可以简单的转变为在将原方程转换为常微分方程组后,进行一个简单的系数判断: 例如: y''' - 3y'' - y'y = 0, y(0) = 0, y'(0) = 0, y''(0) = -1; 在这里可以设  y1 = y, y2 = y', y3 = y'', 有 y1' = y2,  y1(0) = 0, y2' = y3, y2(0) = 1, y3'