Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 许多日食插入_Mysql_Insert_Eclipselink - Fatal编程技术网

Mysql 许多日食插入

Mysql 许多日食插入,mysql,insert,eclipselink,Mysql,Insert,Eclipselink,我认为真正的问题是我无法获得最近持久化的实体的id(我不知道如何)。我正在使用eclipseLink 2.1和mysql 5.1.7,所以我离开了实体类 多对多的联接表是ProductosVentas;对不起,西班牙语的名字 请帮帮我 这是我的剧本 publicstaticvoidmain(字符串参数[]){ EntityManager em=EclipseLinkUtil.getEntityManager工厂(); em.getTransaction().begin(); 试一试{ Query

我认为真正的问题是我无法获得最近持久化的实体的id(我不知道如何)。我正在使用eclipseLink 2.1和mysql 5.1.7,所以我离开了实体类

多对多的联接表是ProductosVentas;对不起,西班牙语的名字

请帮帮我

这是我的剧本

publicstaticvoidmain(字符串参数[]){
EntityManager em=EclipseLinkUtil.getEntityManager工厂();
em.getTransaction().begin();
试一试{
Query=em
.createQuery(“来自Productos p,其中p.nombre类似于'Lavado de motor'”);
Productos selledItem=(Productos)query.getSingleResult();
query=em.createNativeQuery(“选择curdate()”);
java.sql.Date sellingDate=(Date)query.getSingleResult();
Ventas v1=新Ventas();
v1.SetConditionInventaidConditionInventa(新ConditionInventa(1));
v1.setFecha(销售日期);
List selledItemTableList=new ArrayList();
v1.setProductosventasCollection(selledItemTableList);
Productosventas p=新Productosventas();
p、 setVentas(v1);
p、 setCantidad(1);
p、 setProductos(selledItem);
selledItemTableList.add(p);
em.persist(v1);
em.p;
em.getTransaction().commit();
}捕获(例外e){
e、 printStackTrace();
em.getTransaction().rollback();
}最后{
em.close();
}
}
错误

内部异常:com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:
列'ventas_idventa'不能为空 错误代码:1048 调用:在productosventas(cantidad、ventas_idventa、productos_idProductos、PriceModifiers_idPriceModifier)中插入值(?, ?, ?) 绑定=>[4个参数绑定]

这些是我的实体

@实体
@表(name=“productos”)
@XmlRootElement
公共类Productos实现了可序列化{
@OneToMany(cascade=CascadeType.ALL,mappedBy=“productos”)
私人收藏产品私人收藏;
私有静态最终长serialVersionUID=1L;
@身份证
@GeneratedValue(策略=GenerationType.IDENTITY)
@基本(可选=假)
@列(name=“idProductos”)
私有整数idProductos;
//[物业]
@JoinColumn(name=“PriceModifiers\u idPriceModifier”,
referencedColumnName=“idPriceModifier”)
@多通(可选=假)
private Pricemodifiers PriceModifier PriceModifier PriceModifier;
@JoinColumn(name=“AreaServicio_idAreaServicio”,
referencedColumnName=“IDreaServicio”)
@多通(可选=假)
私人区域服务区域服务区域服务区域服务;
@JoinColumn(name=“formaventa\u idFormaVenta”,
referencedColumnName=“idFormaVenta”)
@多通(可选=假)
私人形式的形式的形式;
//接球手和二传手
@XmlTransient
公共集合getProductosventasCollection(){
退货产品回收;
}
public void setProductosventasCollection(
收集产品(收集){
this.productosventasCollection=productosventasCollection;
}
}
@实体
@表(name=“ventas”)
@XmlRootElement
公共类Ventas实现可序列化{
@OneToMany(cascade=CascadeType.ALL,mappedBy=“ventas”)
私人收藏产品私人收藏;
私有静态最终长serialVersionUID=1L;
@身份证
@GeneratedValue(策略=GenerationType.IDENTITY)
@基本(可选=假)
@列(name=“idventa”)
私有整数idventa;
@列(name=“fecha”)
@时态(TemporalType.TIMESTAMP)
私人约会费恰;
@JoinColumn(name=“condicinventa\u idcondicinventa”,
referencedColumnName=“idConditionInventa”)
@多通(可选=假)
私人条件conventa conventa conventa conventa;
@JoinColumn(name=“climas\u idclimas”,referencedColumnName=“idclimas”)
@多通(可选=假)
私人高潮;
@JoinColumn(name=“cliente\u idcliente”,referencedColumnName=“idcliente”)
@多通(可选=假)
私人客户;私人客户;
@JoinColumn(name=“cars\u numberplate”,referencedColumnName=“numberplate”)
@多通(可选=假)
私家车车板;
//接球手和接球手
@XmlTransient
公共集合getProductosventasCollection(){
退货产品回收;
}
public void setProductosventasCollection(
收集产品(收集){
this.productosventasCollection=productosventasCollection;
}
}
@实体
@表(name=“productosventas”)
@XmlRootElement
公共类Productosventas实现可序列化{
私有静态最终长serialVersionUID=1L;
@嵌入ID
受保护产品OSVENTASPK ProductosventasPK;
@列(name=“cantidad”)
私有整数cantidad;
@JoinColumn(name=“PriceModifiers\u idPriceModifier”,
referencedColumnName=“idPriceModifier”)
@多通(可选=假)
private Pricemodifiers PriceModifier PriceModifier PriceModifier;
@JoinColumn(name=“ventas\u idventa”,referencedColumnName=“idventa”,
可插入=false,可更新=false)
@多通(可选=假)
私人文塔斯文塔斯;
@JoinColumn(name=“productos\u idProductos”,
referencedColumnName=“idProductos”,可插入=false,
可更新=错误)
@多通(可选=假)
私人产品;
public Productosventas(){}
公共产品文塔(ProductosventasPK ProductosventasPK){
this.productosventasPK=productosventasPK;
}
公共产品文塔(int文塔西文塔,int productosidProductos){
this.productosventasPK=新产品osventaspk(ventasIdventa,
productosidProductos);
}
公共产品OSVENTASPK getProductosventasPK(){
R