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.
相关问答
更多-
有什么数据库专业书籍介绍?[2022-05-19]
mysql -
插入如果不存在MySQL(Insert into if not exist MySQL)[2023-09-21]
这是你的代码。 IF语句用于比较,你的只是获取数组,你的IF语句中没有任何条件。 您需要修复语句以获取列及其各自的值。 $check_for_episode = mysqli_query($conn, "SELECT DISTINCT house_number,number FROM episode WHERE house_number LIKE '".$house_number."' AND number = ".$episode_id_pg." LIMIT 1"); if (mysqli_fetc ... -
-
可能是冲突.. 2个并发请求,因此一个请求可以删除另一个请求使用的表 尝试将CREATE TABLE更改为CREATE TEMPORARY TABLE May be conflicts.. 2 simultaneous requests, so one request can drop table that is used by another request Try to change CREATE TABLE to CREATE TEMPORARY TABLE
-
您可以使用:在重复键更新名称=值(名称),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=va ...
-
尝试这个: INSERT INTO users (username, first_name, last_name, email, password, sign_up_date, activated) VALUES ('$un','$fn','$ln','$em','$pswd','$d','0')` 如果您的id列是自动增量,则不需要自己填写。 对于您的日期,您可以查看此链接以获取日期参考。 date结构化列需要YY-MM-DD格式,您可以通过以下方式获取: $d = date("Y-m-d"); 您系 ...
-
如果值不存在,如何将数据插入SQLite数据库?(How to insert data into a SQLite Database only if the value does not exist?)[2023-06-11]
使值唯一,然后在插入期间检查数据库值是否已存在。 喜欢这个 : 检查方法: public boolean dataExists(int id) { SQLiteDatabase db = this.getReadableDatabase(); String Query = "SELECT * FROM " + TABLE_NAME + " WHERE " + KEY_QUESION_ID + "=" + id; Cursor cursor = db.rawQu ... -
使用PHP非空的输入将数据插入MySQL数据库(Insert data into MySQL database from inputs that are not empty with PHP)[2022-02-28]
你在那里做了很多插页! 你应该只做一次插入! 尝试使用以下内容替换else语句: else { if($userDesc AND $userLocation AND $userBirthDate AND $user_picture_name != '') { if($userDesc = ''){$userDesc = 'Placeholder description';} if($userLocation = ''){$userLocation = 'Placeh ... -
您只需在描述字段中添加UNIQUE约束即可。 然后在代码中使用“INSERT ... ON DUPLICATE KEY UPDATE”。 请参阅此链接 。 You would simply add a UNIQUE constraint to the description field. and then use "INSERT ... ON DUPLICATE KEY UPDATE" in your code. Refer this link.
-
如果不存在则插入数据(Insert data if not exist)[2023-05-18]
正确的语法是INSERT IGNORE INTO INSERT IGNORE INTO ref_users (id) VALUES ('$id') 如果值不存在,它将插入,如果存在,则忽略该语句。 请注意,这仅在id键时才有效 编辑:从您的评论看来,使用ON DUPLICATE KEY UPDATE会更好。 试试这个查询 INSERT INTO ref_users(id, ref_code) VALUES ('$id', '$ref_code') ON DUPLICATE KEY UPDATE ref_c ...