(Hibernate的Oracle不能插入NULL)如何插入自动生成的ID?(( Hibernate Oracle cannot insert NULL ) How to insert auto generated ID?)
我正在使用hibernate执行CRUD操作的项目。 我有用户模型,我试图插入信息,但不断收到此错误
Hibernate: insert into APPUSER (dob, email, firstName, lastName, password) values (?, ?, ?, ?, ?) Jun 21, 2016 2:17:07 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions WARN: SQL Error: 1400, SQLState: 23000 Jun 21, 2016 2:17:07 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions ERROR: ORA-01400: cannot insert NULL into ("MYAPP8785"."APPUSER"."ID")
用户模型看起来像
@Entity @Table(name="APPUSER") public class AppUser { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; @Email @Size(max = 50) private String email; @Column private String dob; @Column private String firstName; @Column private String lastName; @Column(name = "password", nullable = false) private String password; }
Hibernate的属性就像
properties.put("hibernate.dialect","org.hibernate.dialect.MySQLDialect"); //properties.put("hibernate.current_session_context_class","thread"); properties.put("hibernate.hbm2ddl.auto","update"); properties.put("hibernate.show_sql","true");
我的印象是hibernate会为我自动生成id并使用sequence插入它们
I am working on project where I am using hibernate to perform CRUD operations. I have user model and I am trying to insert the information but keeping getting this error
Hibernate: insert into APPUSER (dob, email, firstName, lastName, password) values (?, ?, ?, ?, ?) Jun 21, 2016 2:17:07 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions WARN: SQL Error: 1400, SQLState: 23000 Jun 21, 2016 2:17:07 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions ERROR: ORA-01400: cannot insert NULL into ("MYAPP8785"."APPUSER"."ID")
The user model looks like
@Entity @Table(name="APPUSER") public class AppUser { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; @Email @Size(max = 50) private String email; @Column private String dob; @Column private String firstName; @Column private String lastName; @Column(name = "password", nullable = false) private String password; }
Hibernate properties like
properties.put("hibernate.dialect","org.hibernate.dialect.MySQLDialect"); //properties.put("hibernate.current_session_context_class","thread"); properties.put("hibernate.hbm2ddl.auto","update"); properties.put("hibernate.show_sql","true");
I am under the impression that hibernate would auto generate id for me and insert them using sequence
原文:https://stackoverflow.com/questions/37936968
最满意答案
两种方法:
当缓冲区已满时写出缓冲区
首先,在脚本开头设置
match_max
。 然后set file "/tmp/b" set log [open $file w] # ... send "$data\r" expect { full_buffer {puts $log $expect_out(buffer); exp_continue} "end_expect" exit } puts $log $expect_out(buffer) close $log expect_eof
而且工作少得多,使用
log_file
记录你关心的部分。不要打扰
match_max
,和set file "/tmp/b" # ... log_file $file send "$data\r" expect { "end_expect" exit } expect_eof
Two ways to approach this:
write out the buffer when it's full
First, set
match_max
at the start of your script. Thenset file "/tmp/b" set log [open $file w] # ... send "$data\r" expect { full_buffer {puts $log $expect_out(buffer); exp_continue} "end_expect" exit } puts $log $expect_out(buffer) close $log expect_eof
and much less work, use
log_file
to log the parts you care about.Don't bother with
match_max
, andset file "/tmp/b" # ... log_file $file send "$data\r" expect { "end_expect" exit } expect_eof
相关问答
更多-
在openssh-client安装上spawn后,你必须expect一些东西,以便expect等待它。 此外, expect不会打扰任何事情,只会退出。 在这种情况下,我们可以等待eof确认安装已完成。 #!/usr/bin/expect spawn sudo mkdir /usr/lib/jvm1 # This will match the ": " at the end. That is why $ symbol used here. expect ": $"; # It will be more ro ...
-
你正在自动化ssh bash remote_script ,所以你不会得到一个shell提示你可以echo $? - ssh将启动您的脚本然后退出。 您需要做的是获取生成进程的退出状态(ssh应该以远程命令的退出状态退出)。 expect的wait命令可以获得退出状态(以及其他信息) spawn ssh {*}$ssh_opts $user@$ip bash $script {*}$argv expect { "Password:" { send "$password\r"; exp_continu ...
-
期待不等待提示 - 脚本停止而不发送其他命令(Expect not waiting for prompt - script stops without sending other commands)[2022-11-08]
以下通过抑制显示给用户的输出,而不是将其附加到我的log_file来解决我的脚本中的问题: log_file -a initial_commands log_user 0 send "some commands with large output" log_file log_user 1 在这种情况下,用户是否看到输出并不重要,因为我正在解析它并将其输出到文件中。 为了进一步反驳它是我expect "<$"代码中的一个错误,我在运行system "parse.pl"时遇到了同样的行为(完全意外)。 per ... -
修复重复问题; 看下面的更新代码: 期待{-re“(?s) - {30} \ r \ n(。*?) - {30}” {puts $expect_out(0,string) } } Fixed duplication issue; see updated code below: expect { -re "(?s)-{30}\r\n(.*?)-{30}" {puts $expect_out(0,string) } }
-
以下内容适用于OS X Terminal中的单行bash脚本。 它仅用于受防火墙保护的局域网。 在我原来的帖子进一步的细节。 expect -c 'spawn ssh -o StrictHostKeyChecking=no remote-user@remote-IP; expect assword; send remote-password\r; expect remote-user$; send "sudo shutdown -h +1\r"; expect assword; send remote- ...
-
expect - 如果找不到预期的字符串,如何丢弃缓冲区(expect - how to discard the buffer if expected string is not found)[2022-07-14]
这似乎“有效”(需要更多测试): set success_string "\[INFO\] Started Jetty\r\n" spawn "/usr/bin/mvn" "-pl" ":cloud-client-ui" "jetty:run" expect { -re "(\[^\r]*\)\r\n" { set current_line $expect_out(buffer) if { [string equal "$current_line" "$success_strin ... -
请注意,expect实际上是Tcl的扩展。 Tcl的exec执行外部命令, 捕获输出并将其作为值返回 - 除非您指示它,否则它不会将其发送到stdout。 但是, 为方便起见 , 交互式 Tcl(或期望)会话将输出打印到stdout。 你的脚本应该是: puts [exec echo a] # or set output [exec echo a] puts $output 我假设“echo a”是占位符,用于更复杂的外部命令。 如果你只想打印一些东西: puts "this is something" ...
-
壳牌heredocs本质上是大双引号字符串。 在 expect启动之前 , shell将替换$expect_out变量(因为shell会话没有这样的变量,所以使用空字符串)。 您需要单引用expect脚本体来保护shell中的expect变量: expect << 'EOF' # ........^...^ # everything else is the same http://www.gnu.org/software/bash/manual/bashref.html#Here-Documents Sh ...
-
两种方法: 当缓冲区已满时写出缓冲区 首先,在脚本开头设置match_max 。 然后 set file "/tmp/b" set log [open $file w] # ... send "$data\r" expect { full_buffer {puts $log $expect_out(buffer); exp_continue} "end_expect" exit } puts $log $expect_out(buffer) close $log expect_eof 而且 ...
-
按照上面给出的建议,使用send "./script.exp\r" 而不是spawn "./script.exp" ,修复问题。 Following the advice given above, using send "./script.exp\r" instead of spawn "./script.exp", fixes the problem.