- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 grails 的新手,我创建了一个用户域类和用户配置文件域类。而这些类(class)是有亲戚关系的。域类如下所示
class User {
transient springSecurityService
String username
String password
String email
static hasOne = [profile: UserProfile]
boolean enabled = true
boolean accountExpired
boolean accountLocked
boolean passwordExpired
static transients = ['springSecurityService']
static constraints = {
username blank: false, unique: true
password blank: false
email blank: false, nullable: false, unique: true, email: true
profile nullable:true, unique: true
}
class UserProfile {
String firstname;
String team;
String pidgin;
String phone;
User user
static constraints = {
firstname nullable:true
team nullable:false, blank:false
pidgin nullable:false, blank:false
phone nullable:false
}
}
在我的服务类
class UserService{
public User createUserProfile(UserProfile profile,String email) {
User user = User.findByEmail(email)
if(!user)
//no user found
profile.user = user
profile.save()
user.profile = profile
user.save(failOnError: true)
}
}
当运行我的项目时,它完全按照任何方式运行并执行 createUserProfile
但是,当使用相同的函数更新我的用户配置文件 user.save(failOnError: true)
抛出 JdbcSQLException。
详细错误如下。
| Error 2014-03-28 16:21:28,958 [http-bio-8530-exec-8] ERROR util.JDBCExceptionReporter - Unique index or primary key violation: "CONSTRAINT_INDEX_C ON PUBLIC.USER_PROFILE(USER_ID)"; SQL statement:
insert into user_profile (id, version, firstname, phone, pidgin, team, user_id) values (null, ?, ?, ?, ?, ?, ?) [23505-164]
| Error 2014-03-28 16:21:29,065 [http-bio-8530-exec-8] ERROR errors.GrailsExceptionResolver - JdbcSQLException occurred when processing request: [POST] /OrbiFlow/user/profileEditSubmit - parameters:
phone: 4568932158
username: ani
email: anagkt@asdk.com
pidgin: weg
team: sdgv
firstname: qwf
Unique index or primary key violation: "CONSTRAINT_INDEX_C ON PUBLIC.USER_PROFILE(USER_ID)"; SQL statement:
insert into user_profile (id, version, firstname, phone, pidgin, team, user_id) values (null, ?, ?, ?, ?, ?, ?) [23505-164]. Stacktrace follows:
Message: Unique index or primary key violation: "CONSTRAINT_INDEX_C ON PUBLIC.USER_PROFILE(USER_ID)"; SQL statement:
insert into user_profile (id, version, firstname, phone, pidgin, team, user_id) values (null, ?, ?, ?, ?, ?, ?) [23505-164]
Line | Method
->> 329 | getJdbcSQLException in org.h2.message.DbException
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 169 | get in ''
| 146 | get . . . . . . . . . . in ''
| 81 | getDuplicateKeyException in org.h2.index.BaseIndex
| 62 | add . . . . . . . . . . in org.h2.index.TreeIndex
| 50 | add in org.h2.index.MultiVersionIndex
| 121 | addRow . . . . . . . . . in org.h2.table.RegularTable
| 124 | insertRows in org.h2.command.dml.Insert
| 84 | update . . . . . . . . . in ''
| 73 | update in org.h2.command.CommandContainer
| 226 | executeUpdate . . . . . in org.h2.command.Command
| 143 | executeUpdateInternal in org.h2.jdbc.JdbcPreparedStatement
| 129 | executeUpdate . . . . . in ''
| 105 | executeUpdate in org.apache.commons.dbcp.DelegatingPreparedStatement
| 83 | createUserProfile . . . in com.orb.user.UserService
| 178 | profileEditSubmit in com.orb.user.UserController
| 195 | doFilter . . . . . . . . in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 53 | doFilter . . . . . . . . in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
| 49 | doFilter in grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter
| 82 | doFilter . . . . . . . . in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
| 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
| 908 | run . . . . . . . . . . in ''
^ 662 | run in java.lang.Thread
如何消除这个异常..或错误
提前致谢
最佳答案
尝试保存域并引用未保存并尝试引用的对象时发生约束错误。所以做一些欺骗性的例子,比如:你也应该制作唯一的用户
new Face(nose:new Nose()).save()
上面的例子将保存面部和 Nose 。请注意,反之则不然,会因 transient 面而导致错误:
焦点:消息:唯一索引或主键违规:“CONSTRAINT_INDEX_C ON PUBLIC.USER_PROFILE(USER_ID)”; SQL语句:
关于grails JdbcSQLException 在保存一对一映射领域类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22711625/
我是 grails 的新手,我创建了一个用户域类和用户配置文件域类。而这些类(class)是有亲戚关系的。域类如下所示 class User { transient springSecurit
每当我尝试执行包含超过 40 个测试的测试类时,多余的测试都会失败。测试类由43个测试组成。无论我删除哪三个测试,其余的测试都会运行绿色。 使用的框架: 朱尼特 Mockmvc h2 数据库 堆栈跟踪
我在 MS SQL Server 中有一个从 Java 代码调用的用户定义函数,在 H2 数据库中运行集成测试时该函数似乎未定义。你可以在 the previous question 找到我的代码.
我用另一个应该连接到内存数据库的配置替换了一个连接到真实数据库的配置。我想使用此配置进行集成测试。一个简单的测试如下所示 import org.junit.Test; import org.junit
我想设置一个计数器来从数据库中获取记录数: String sql = " select count(*) as counter from CLIENT "; conn = DBConnector.ge
我正在尝试使用嵌入式 h2 数据库运行我的应用程序。 我收到以下错误: Caused by: org.springframework.jdbc.BadSqlGrammarException: Prep
我是 Grails 的新手,不太熟悉 GORM 如何将列映射到 jdbc 实现。 基本上我有以下错误: org.h2.jdbc.JdbcSQLException 信息: Value too long
我正在尝试编写一个内存数据库来测试我的 DAO 对象。我得到以下堆栈跟踪: Caused by: org.h2.jdbc.JdbcSQLException: Syntax error in SQL s
我已经设置了以下 POJO: @Getter @Setter @AllArgsConstructor @Entity @Table(name = "SpreadsheetRequest") publi
这是 Hibernate version mismatch in WildFly 10.0 的后续问题。 为了完整起见,简要重述问题。我有2个项目,一个是普通的java项目(带有maven):core
我参与了一个 Spring Boot 项目,该项目读取 CSV 文件并将数据保存在 H2 数据库中。 下面提供了 CSV 文件 - authors.csv email;firstname;lastna
在java中使用h2(调用getBytes函数)时,我收到以下错误。谷歌没有找到我任何地方。我想知道是否有人知道发生了什么事。 Caused by: org.h2.jdbc.JdbcSQLExcept
所以简短的版本,我猜我有某种字符编码问题,或者数据库正在以 Hibernate/Spring-jpa 出于某种原因不喜欢的格式存储/返回日期。 但如果我能弄清楚哪里出了问题,我会很兴奋! 使用 Hib
几天以来,我一直在努力解决这个问题,但并未真正了解其背后的原因。 使用 Liquibase、PostgreSQL 和 H2DB(用于测试)。 Liquibase 在使用 PostgreSQL 时工作正
我已经尝试过在网上找到的一些解决方案,但都没有奏效。我正在使用内存中持久 hibernate 数据库。 @Entity @Table(name = "Users") public class User
尝试使用以下 URL 创建 H2 数据库连接时, Connection conn = DriverManager.getConnection("jdbc:h2:D:/HATBOX/Data;AUTO
我在内存数据库中使用 H2 和 play 框架 我是初学者所以我决定制作一个小的登录注册应用程序来开始使用 scala 并玩我决定在内存数据库中使用 H2 但它抛出 Table未找到异常我在 sql
我在 openshift 上部署应用程序时遇到下一个问题。我使用 wildfly 应用程序服务器和 PostgreSQL cartrige。 在 persistence.xml 中,我设置了属性“hi
我正在尝试以开发模式(使用 H2)运行当前在生产环境中使用 PostgreSQL 数据库的设置,但出现错误。如果我可以在不进行任何更改的情况下重用生产 SQL,那将是最好的。 使用此设置: # H2
Spring Boot 1.1.5.RELEASE public class DataAccessTests { private EmbeddedDatabase db; @Befor
我是一名优秀的程序员,十分优秀!