- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个User类,每个用户实例都有一个配置文件。该配置文件具有一个我想更新的avatarImage属性。我能够在运行时更新用户的字段,但不能更新该用户的个人资料的字段。我正在使用springsecurity获取currentUser,并且想更新他的avatarImage,但是在运行时得到了SQLException。
用户域类:
package com.clinton.kiitsocial
import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString
@EqualsAndHashCode(includes='username')
@ToString(includes='username', includeNames=true, includePackage=false)
class User implements Serializable {
private static final long serialVersionUID = 1
transient springSecurityService
//don't touch this...for spring-security
String username
String password
boolean enabled = true
boolean accountExpired
boolean accountLocked
boolean passwordExpired
//starting custom domain...can touch this
Integer uniqueId
Date dateCreated
Date lastUpdated
static hasMany = [contents: Content]
static hasOne = [profile: Profile]
User(String username, String password) {
this()
this.username = username
this.password = password
}
Set<Role> getAuthorities() {
UserRole.findAllByUser(this)*.role
}
def beforeInsert() {
encodePassword()
}
def beforeUpdate() {
if (isDirty('password')) {
encodePassword()
}
}
protected void encodePassword() {
password = springSecurityService?.passwordEncoder ? springSecurityService.encodePassword(password) : password
}
static transients = ['springSecurityService']
static constraints = {
username blank: false, unique: true
password blank: false, minSize: 5, validator: { pass, user ->
pass != user.username
}
uniqueId blank: false, unique: true, range: 1000..2000000000
profile unique: true, nullable: true
contents nullable: true
}
static mapping = {
password column: '`password`'
profile fetch: 'join'
}
package com.clinton.kiitsocial
class Profile {
String bio
String contact
String address
GenderList gender
String emailId
Avatar avatarImage
User user
static hasMany = [socialNetworks: Social]
static constraints = {
bio nullable: true, maxSize: 50
address nullable: true, maxSize: 50
contact nullable: true, matches: "^\\+(?:[0-9] ?){6,14}[0-9]\$"
socialNetworks nullable: true, unique: true
gender nullable: true, blank: false
emailId email: true, blank: true
avatarImage nullable: true
}
}
@Secured(['ROLE_ADMIN', 'ROLE_USER'])
class UserController extends RestfulController {
static responseFormats = ['json', 'xml']
def userService
UserController() {
super(User)
}
def uploadAvatar() {
MultipartFile avatar = request.getFile('avatar')
avatar ? respond (userService.uploadingAvatar(avatar)): respond (500)
}
def showAvatar() {
}
}
package com.clinton.kiitsocial
import grails.plugin.springsecurity.SpringSecurityService
import grails.transaction.Transactional
import org.springframework.web.multipart.MultipartFile
@Transactional
class UserService {
SpringSecurityService springSecurityService
private static final acceptedAvatarTypes = ['image/png', 'image/jpeg', 'image/gif']
User uploadingAvatar(MultipartFile file) {
User user = (User) springSecurityService.currentUser
Profile profile = Profile.findOrSaveByUser(user)
assert profile.user.username == user.username
//assert !profile.avatarImage
String message = ""
if (!acceptedAvatarTypes.contains(file.contentType)) {
//message = "Avatar must be one of: ${acceptedAvatarTypes} type"
//respond 500
return user
}
profile.avatarImage = new Avatar(avatar: file.bytes, avatarType: file.contentType)
println("uploading: ${profile.avatarImage.avatarType}")
if (!profile.save(failOnError: true, flush: true)) { //Error ocurs here
message = "error occurred saving image"
println("${profile.errors}")
//respond user.errors
return user
}
message = "Avatar (${profile.avatarImage.avatarType}, ${profile.avatarImage.avatar.size()} bytes) uploaded."
println(message)
println("finishing...")
return user
}
/*def showAvatar(long userId) {
def avatarUser = User.get(userId)
if (!avatarUser || !avatarUser.profile.avatarImage || !avatarUser.profile.avatarType) {
//respond 404
return
}
response.contentType = avatarUser.profile.avatarType
response.contentLength = avatarUser.profile.avatarImage.size()
OutputStream out = response.outputStream
out.write(avatarUser.profile.avatarImage)
out.close()
}*/
}
uploading: image/png 2016-12-17 12:27:48.668 ERROR --- [nio-8080-exec-9] o.h.engine.jdbc.spi.SqlExceptionHelper : Parameter "#1" is not set; SQL statement: select this_.id as id1_3_0_, this_.version as version2_3_0_, this_.address as address3_3_0_, this_.avatar_image_id as avatar_i4_3_0_, this_.bio as bio5_3_0_, this_.contact as contact6_3_0_, this_.email_id as email_id7_3_0_, this_.gender as gender8_3_0_, this_.user_id as user_id9_3_0_ from profile this_ where this_.id=? [90012-192] 2016-12-17 12:27:48.711 ERROR --- [nio-8080-exec-9] o.g.web.errors.GrailsExceptionResolver : JdbcSQLException occurred when processing request: [POST] /api/avatars Parameter "#1" is not set; SQL statement: select this_.id as id1_3_0_, this_.version as version2_3_0_, this_.address as address3_3_0_, this_.avatar_image_id as avatar_i4_3_0_, this_.bio as bio5_3_0_, this_.contact as contact6_3_0_, this_.email_id as email_id7_3_0_, this_.gender as gender8_3_0_, this_.user_id as user_id9_3_0_ from profile this_ where this_.id=? [90012-192]. Stacktrace follows:
java.lang.reflect.InvocationTargetException: null at org.grails.core.DefaultGrailsControllerClass$ReflectionInvoker.invoke(DefaultGrailsControllerClass.java:210) at org.grails.core.DefaultGrailsControllerClass.invoke(DefaultGrailsControllerClass.java:187) at org.grails.web.mapping.mvc.UrlMappingsInfoHandlerAdapter.handle(UrlMappingsInfoHandlerAdapter.groovy:90) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:115) at grails.plugin.springsecurity.rest.RestAuthenticationFilter.doFilter(RestAuthenticationFilter.groovy:143) at grails.plugin.springsecurity.rest.RestLogoutFilter.doFilter(RestLogoutFilter.groovy:80) at grails.plugin.springsecurity.rest.RestTokenValidationFilter.processFilterChain(RestTokenValidationFilter.groovy:118) at grails.plugin.springsecurity.rest.RestTokenValidationFilter.doFilter(RestTokenValidationFilter.groovy:84) at org.springframework.boot.web.filter.ApplicationContextHeaderFilter.doFilterInternal(ApplicationContextHeaderFilter.java:55) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:317) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:115) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) at grails.plugin.springsecurity.rest.RestTokenValidationFilter.processFilterChain(RestTokenValidationFilter.groovy:118) at grails.plugin.springsecurity.rest.RestTokenValidationFilter.doFilter(RestTokenValidationFilter.groovy:84) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:169) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) at grails.plugin.springsecurity.rest.RestAuthenticationFilter.doFilter(RestAuthenticationFilter.groovy:143) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) at grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter.doFilter(MutableLogoutFilter.groovy:62) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) at grails.plugin.springsecurity.web.SecurityRequestHolderFilter.doFilter(SecurityRequestHolderFilter.groovy:58) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214) at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177) at org.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:77) at org.grails.web.filters.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:67) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: could not extract ResultSet; uncategorized SQLException for SQL [n/a]; SQL state [90012]; error code [90012]; Parameter "#1" is not set; SQL statement: select this_.id as id1_3_0_, this_.version as version2_3_0_, this_.address as address3_3_0_, this_.avatar_image_id as avatar_i4_3_0_, this_.bio as bio5_3_0_, this_.contact as contact6_3_0_, this_.email_id as email_id7_3_0_, this_.gender as gender8_3_0_, this_.user_id as user_id9_3_0_ from profile this_ where this_.id=? [90012-192]; nested exception is org.h2.jdbc.JdbcSQLException: Parameter "#1" is not set; SQL statement: select this_.id as id1_3_0_, this_.version as version2_3_0_, this_.address as address3_3_0_, this_.avatar_image_id as avatar_i4_3_0_, this_.bio as bio5_3_0_, this_.contact as contact6_3_0_, this_.email_id as email_id7_3_0_, this_.gender as gender8_3_0_, this_.user_id as user_id9_3_0_ from profile this_ where this_.id=? [90012-192] at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:84) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) at org.grails.orm.hibernate.GrailsHibernateTemplate.convertJdbcAccessException(GrailsHibernateTemplate.java:668) at org.grails.orm.hibernate.GrailsHibernateTemplate.convertHibernateAccessException(GrailsHibernateTemplate.java:656) at org.grails.orm.hibernate.GrailsHibernateTemplate.doExecute(GrailsHibernateTemplate.java:247) at org.grails.orm.hibernate.GrailsHibernateTemplate.execute(GrailsHibernateTemplate.java:187) at org.grails.orm.hibernate.GrailsHibernateTemplate.execute(GrailsHibernateTemplate.java:110) at org.grails.orm.hibernate.validation.UniqueConstraint.processValidate(UniqueConstraint.java:149) at grails.validation.AbstractConstraint.validate(AbstractConstraint.java:107) at grails.validation.ConstrainedProperty.validate(ConstrainedProperty.java:979) at org.grails.validation.GrailsDomainClassValidator.validatePropertyWithConstraint(GrailsDomainClassValidator.java:211) at org.grails.validation.GrailsDomainClassValidator.validate(GrailsDomainClassValidator.java:81) at org.grails.orm.hibernate.AbstractHibernateGormInstanceApi.save(AbstractHibernateGormInstanceApi.groovy:122) at org.grails.datastore.gorm.GormEntity$Trait$Helper.save(GormEntity.groovy:151) at com.clinton.kiitsocial.UserService$$EQ5cdaRc.$tt__uploadingAvatar(UserService.groovy:26) at grails.transaction.GrailsTransactionTemplate$2.doInTransaction(GrailsTransactionTemplate.groovy:96) at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133) at grails.transaction.GrailsTransactionTemplate.execute(GrailsTransactionTemplate.groovy:93) at com.clinton.kiitsocial.UserController$$EQ5ccaGm.uploadAvatar(UserController.groovy:20) ... 38 common frames omitted Caused by: org.h2.jdbc.JdbcSQLException: Parameter "#1" is not set; SQL statement: select this_.id as id1_3_0_, this_.version as version2_3_0_, this_.address as address3_3_0_, this_.avatar_image_id as avatar_i4_3_0_, this_.bio as bio5_3_0_, this_.contact as contact6_3_0_, this_.email_id as email_id7_3_0_, this_.gender as gender8_3_0_, this_.user_id as user_id9_3_0_ from profile this_ where this_.id=? [90012-192] at org.h2.message.DbException.getJdbcSQLException(DbException.java:345) at org.h2.message.DbException.get(DbException.java:179) at org.h2.message.DbException.get(DbException.java:155) at org.h2.expression.Parameter.checkSet(Parameter.java:81) at org.h2.command.Prepared.checkParameters(Prepared.java:164) at org.h2.command.CommandContainer.query(CommandContainer.java:109) at org.h2.command.Command.executeQuery(Command.java:201) at org.h2.jdbc.JdbcPreparedStatement.executeQuery(JdbcPreparedStatement.java:110) at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:70) at org.hibernate.loader.Loader.getResultSet(Loader.java:2122) at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1905) at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1881) at org.hibernate.loader.Loader.doQuery(Loader.java:925) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:342) at org.hibernate.loader.Loader.doList(Loader.java:2622) at org.hibernate.loader.Loader.doList(Loader.java:2605) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2434) at org.hibernate.loader.Loader.list(Loader.java:2429) at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:109) at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1787) at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:363) at org.grails.orm.hibernate.validation.UniqueConstraint$2.call(UniqueConstraint.java:210) at org.grails.orm.hibernate.validation.UniqueConstraint$2.call(UniqueConstraint.java:149) at org.grails.orm.hibernate.GrailsHibernateTemplate.doExecute(GrailsHibernateTemplate.java:243) ... 52 common frames omitted
最佳答案
我想到了。我对其进行了集成测试,发现:休眠需要将内部域持久化并刷新,然后再将其附加到父域。喜欢自下而上的时尚。请参阅下面的答案。它是由瞬时域实例引起的。
Avatar uploadingAvatar(MultipartFile file) {
User user = (User) springSecurityService.currentUser
if (!user.profile) user.profile = new Profile(user: user).save(flush: true)
if (!acceptedAvatarTypes.contains(file.contentType)) {
responseCode = 500
}
Avatar avatar = user.profile.avatarImage ?: new Avatar()
avatar.avatarName = file.originalFilename
avatar.avatarBytes = file.bytes
avatar.avatarType = file.contentType
if (!avatar.validate() && !avatar.save(flush: true)){
responseCode = 500
return avatar
}
user.profile.avatarImage = avatar
println("Avatar changed success")
responseCode = 200
return avatar
}
关于hibernate - 无法以一对一关系更新拥有方的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41196318/
我查看了网站上的一些问题,但还没有完全弄清楚我做错了什么。我有一些这样的代码: var mongoose = require('mongoose'), db = mongoose.connect('m
基本上,根据 this bl.ocks,我试图在开始新序列之前让所有 block 都变为 0。我认为我需要的是以下顺序: 更新为0 退出到0 更新随机数 输入新号码 我尝试通过添加以下代码块来遵循上述
我试图通过使用随机数在循环中设置 JSlider 位置来模拟“赛马”的投注结果。我的问题是,当然,我无法在线程执行时更新 GUI,因此我的 JSlider 似乎没有在竞赛,它们从头到尾都在运行。我尝试
该功能非常简单: 变量:$table是正在更新的表$fields 是表中的字段,$values 从帖子生成并放入 $values 数组中而$where是表的索引字段的id值$indxfldnm 是索引
让我们想象一个环境:有一个数据库客户端和一个数据库服务器。数据库客户端可以是 Java 程序或其他程序等;数据库服务器可以是mysql、oracle等。 需求是在数据库服务器上的一个表中插入大量记录。
在我当前的应用程序中,我正在制作一个菜单结构,它可以递归地创建自己的子菜单。然而,由于这个原因,我发现很难也允许某种重新排序方法。大多数应用程序可能只是通过“排序”列进行排序,但是在这种情况下,尽管这
Provisioning Profile 有 key , key 链依赖于它。我想知道 key 什么时候会改变。 Key will change after renew Provisioning Pr
截至目前,我在\server\publications.js 中有我的 MongoDB“选择”,例如: Meteor.publish("jobLocations", function () { r
我读到 UI 应该始终在主线程上更新。但是,当谈到实现这些更新的首选方法时,我有点困惑。 我有各种函数可以执行一些条件检查,然后使用结果来确定如何更新 UI。我的问题是整个函数应该在主线程上运行吗?应
我在代理后面,我无法构建 Docker 镜像。 我试过 FROM ubuntu , FROM centos和 FROM alpine ,但是 apt-get update/yum update/apk
我构建了一个 Java 应用程序,它向外部授权客户端公开网络服务。 Web 服务使用带有证书身份验证的 WS-security。基本上我们充当自定义证书颁发机构 - 我们在我们的服务器上维护一个 ja
因此,我有时会在上传新版本时使用 app_offline.htm 使应用程序离线。 但是,当我上传较大的 dll 时,我收到黄色错误屏幕,指出无法加载 dll。 这似乎与我对 app_offline.
我刚刚下载了 VS Apache Cordova Tools Update 5,但遇到了 Node 和 NPM 的问题。我使用默认的空白 cordova 项目进行测试。 版本 如果我在 VS 项目中对
所以我有一个使用传单库实例化的 map 对象。 map 实例在单独的模板中创建并以这种方式路由:- var app = angular.module('myApp', ['ui', 'ngResour
我使用较早的 Java 6 u 3 获得的帧速率是新版本的两倍。很奇怪。谁能解释一下? 在 Core 2 Duo 1.83ghz 上,集成视频(仅使用一个内核)- 1500(较旧的 java)与 70
我正在使用 angular 1.2 ng-repeat 创建的 div 也包含 ng-click 点击时 ng-click 更新 $scope $scope 中的变化反射(reflect)在使用 $a
这些方法有什么区别 public final void moveCamera(CameraUpdate更新)和public final void animateCamera (CameraUpdate
我尝试了另一篇文章中某人评论中关于如何将树更改为列表的建议。但是,我在某处(或某物)有未声明的变量,所以我列表中的值是 [_G667, _G673, _G679],而不是 [5, 2, 6],这是正确
实现以下场景的最佳方法是什么? 我需要从java应用程序调用/查询包含数百万条记录的数据库表。然后,对于表中的每条记录,我的应用程序应该调用第三方 API 并获取状态字段作为响应。然后我的应用程序应该
只是在编写一些与 java 图形相关的代码,这是我今天的讲座中的非常简单的示例。不管怎样,互联网似乎说更新不会被系统触发器调用,例如调整框架大小等。在这个例子中,更新是由这样的触发器调用的(因此当我只
我是一名优秀的程序员,十分优秀!