我的数据库中有以下两个表:
日历(id,name,user_id)
用户(id,name,...)
每个日历由一个用户拥有,每个用户可以拥有多个日历.因此,从日历到用户之间存在多对一关系.现在我想在我的Calendar表中插入一组数据,我的Calendar Entity如下所示:
@Entity
@Table(name = "calendar")
public class Calendar {
@Id
@GeneratedValue(generator = "uuid2")
@GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(name = "id", columnDefinition = "BINARY(16)")
private UUID id;
@Column(name = "name")
private String name;
@ManyToOne
@JoinColumn(name = "owner", referencedColumnName = "id")
private User owner;
...
}
Run Code Online (Sandbox Code Playgroud)
但是,当我插入数据集时,我确实知道所有者的id,但我没有相应的User对象.我是否必须检索User对象,设置owner它然后插入数据集?
这对我来说听起来有点不方便,有没有办法使用Userid 插入数据集,因为它将存储在数据库中,而不是使用User对象?
我需要从 JSON 模式文件生成 Java 类,并遇到了 jsonschema2pojo。然而,我在使用关键字时遇到了“问题” ref。
例如,如果我使用http://spacetelescope.github.io/understanding-json-schema/structuring.html#extending中的以下架构:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {
"address": {
"type": "object",
"properties": {
"street_address": { "type": "string" },
"city": { "type": "string" },
"state": { "type": "string" }
},
"required": ["street_address", "city", "state"]
}
},
"type": "object",
"properties": {
"billing_address": { "$ref": "#/definitions/address" },
"shipping_address": { "$ref": "#/definitions/address" }
}
}
Run Code Online (Sandbox Code Playgroud)
正如预期的那样,它生成了一个类,无论您想如何称呼它,都可以命名它,其中包含一个 attributebillingAddress和一个 attribute shippingAddress。
然而,它还生成了两个单独的类BillingAddress,ShippingAddress即使这两个属性都引用address. 因此,我宁愿同时拥有 type 的两个属性Address。
这可以用 …
从Spring 3迁移到Spring 4之后,请求页面时出现以下错误:
java.lang.NoSuchMethodError: org.springframework.web.context.request.ServletRequestAttributes.<init>(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V
Run Code Online (Sandbox Code Playgroud)
我仔细检查了一下,该方法似乎在Spring 4中不存在。我想知道是否弄乱了我web.xml或我的某些xsd版本dispatcher-servlet.xml
这是我的web.xml:
java.lang.NoSuchMethodError: org.springframework.web.context.request.ServletRequestAttributes.<init>(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V
Run Code Online (Sandbox Code Playgroud)
dispatcher-servlet.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
</web-app>
Run Code Online (Sandbox Code Playgroud)
而我的pom.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd">
<context:component-scan base-package="org.javacms.controllers" />
<mvc:resources mapping="/templates/**" location="/templates/" />
<!-- added to avoid …Run Code Online (Sandbox Code Playgroud) 在我的Spring Boot应用程序中,我正在使用snakeyaml来解析YAML文件。使用库时出现以下错误:
java.lang.NoSuchMethodError: org.yaml.snakeyaml.nodes.ScalarNode.getStyle()Ljava/lang/Character;
Run Code Online (Sandbox Code Playgroud)
我正在使用以下Maven依赖项:
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.21</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
有没有人提示您解决此错误?
编辑:
解析spring的application.yml时似乎发生了错误:
server:
port: 8084
Run Code Online (Sandbox Code Playgroud) 在我的 Spring Boot Web 应用程序中,我有一个控制器,它提供了一种从数据库中删除实体的方法,该方法又调用 DAO 类。但是,当我调用 时entityManager.remove(entity),我收到了StaleObjectStateException, 尽管entity刚刚从数据库中检索到,并且没有其他对我的 API 的调用可能已更改entity。
这是我的控制器:
@Transactional
@RestController
public class AppAdminController {
...
@RequestMapping(value = "/admins/{username}", method = RequestMethod.DELETE)
public void deleteAdmin(@PathVariable("username") String username) {
dao.removeByUsername(username);
}
}
Run Code Online (Sandbox Code Playgroud)
道:
@Service
public class AppAdminDao extends AbstractDAO<UUID, AppAdmin> {
public AppAdmin getByUsername(String username) {
TypedQuery<AppAdmin> query = em.createQuery("SELECT a FROM AppAdmin a WHERE a.username=:username", AppAdmin.class);
query.setParameter("username", username);
try {
return query.getSingleResult();
} catch (NoResultException e) {
return null; …Run Code Online (Sandbox Code Playgroud) java ×5
hibernate ×1
jpa ×1
json ×1
snakeyaml ×1
spring ×1
spring-boot ×1
spring-mvc ×1
yaml ×1