ejb3 toplink jpa 1.0查询和id序列策略(ejb3 toplink jpa 1.0 querying and id sequence strategy)
我有两个问题:假设我们有一个名为class的实体,另一个叫做student。 每个班级都有学生。
public class Clas implements Serializable { @Id @GeneratedValue(strategy=GenerationType.SEQUENCE) private int id; @OneToMany(cascade=CascadeType.ALL) Collection<Student> students; public clas(){ super(); } ..... getters and setters }
q1:我得到异常,由于序列策略没有要映射的字段,当添加任何其他列如String name时,它可以工作,但我不需要该字段我该怎么办?
Q2。 ids是自动生成的,我想查询类c1中的所有学生,但我没有这个类的id,如何在不使用id的情况下获得这样的查询? 或者如何获取数据库实体id来查询它?
我使用mysql服务器glassfish v2.1 toplink jpa 1.0
谢谢
I have 2 questions: suppose we have one entity named class and another called student. each class has onetomany students.
public class Clas implements Serializable { @Id @GeneratedValue(strategy=GenerationType.SEQUENCE) private int id; @OneToMany(cascade=CascadeType.ALL) Collection<Student> students; public clas(){ super(); } ..... getters and setters }
q1: i get the exception there are no fields to be mapped because of sequence strategy, when adding any other column like String name, it works, but i don't need that field what can i do ?
q2. the ids is autogenerated, and i want to query all students in class c1, but i don't has the id of this class, how to get such query without using id? or how to get database entity id to query on it ?
iam working with mysql server glassfish v2.1 toplink jpa 1.0
Thanks
原文:https://stackoverflow.com/questions/8635695
满意答案
您可以使用:在重复键更新名称=值(名称),firstname = values(firstname)上插入table_name(id,name,firstname)值(1,“Sessi”,“Brahim”)
使其适应您的查询。
You can use: insert into table_name (id, name, firstname) values(1, "Sessi", "Brahim") on duplicate key update name=values(name), firstname=values(firstname)
Adapt it to your query.
相关问答
更多有什么数据库专业书籍介绍?
插入如果不存在MySQL(Insert into if not exist MySQL)
如何插入数据,如果使用coldfuison数据库中不存在该数据?(How to insert data, If that data does not exist in database using coldfuison?)
表不存在于数据库中但它确实存在(Table doesn't Exist in database but it does)
如果不存在,则将数据插入mysql数据库(Insert data to mysql database if not exist)
无法将数据插入MySQL数据库(Cannot insert data into MySQL Database)
如果值不存在,如何将数据插入SQLite数据库?(How to insert data into a SQLite Database only if the value does not exist?)
使用PHP非空的输入将数据插入MySQL数据库(Insert data into MySQL database from inputs that are not empty with PHP)
如果数据不存在(不包括主键),则插入MySQL(MySQL insert if data doesn't exist(excluding primary key))
如果不存在则插入数据(Insert data if not exist)
相关文章
更多JPA ORM框架介绍
【第八章】 对ORM的支持 之 8.4 集成JPA ——跟我学spring3
hibernate id 生成策略及主要使用方法
Hibernate Search(基于version3.4)--第五章Querying
JPA高级映射(继承)
JPA一对多、一对一、多对一、多对多实体关系
JPA 增删改查入门示例
传智播客JPA详解视频教程
spring 3.0 和jpa 整合 用jboss
JPA标准API-JPQL查询的另一种方式
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!