我是JPA和Hibernate的新手,我遇到了乐观锁定的问题.我有一个有@Version注释字段的课程.当我更新此类所代表的实体时,版本计数器不会增加.这是我的代码:班级:
@Entity
@Table (name = "Studenten")
public class Student implements Serializable{
private static final long serialVersionUID = 705252921575133272L;
@Version
private int version;
private int matrnr;
private String name;
private int semester;
public Student (){
}
public Student (int matrnr, String name){
this.matrnr = matrnr;
this.name = name;
}
public Student (int matrnr, String name, int semester){
this(matrnr, name);
this.semester = semester;
}
Run Code Online (Sandbox Code Playgroud)
这是主要方法:
public static void main(String[] args) {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("VEDA_Vortrag");
EntityManager em = emf.createEntityManager();
EntityTransaction tx = …
Run Code Online (Sandbox Code Playgroud) 我玩过弹簧证券方法安全性并得到了一个非常奇怪的行为。我有几个控制器类,这些方法用 @PreAuthorize 进行注释以限制某些用户角色的访问。
有一个控制器类在添加方法安全性后注入的对象为空。我调试到我的代码中,发现以下内容:
service和userService是注入的对象
@Controller
public class OrderController {
@Autowired
private OrderService service;
@Autowired
private UserService userService;
Run Code Online (Sandbox Code Playgroud)
什么觉得奇怪,我是值描述此:OrderController $$ EnhancerBySpringCGLIB $$ 1a7122f6。通过删除所有 MethodSecurity 注释,该类按预期工作。
当我查看其他也使用方法安全性的控制器类时,它们工作得很好,调试器中的变量列表看起来也不错:
@Controller
public class UserController {
@Autowired
private UserService service;
Run Code Online (Sandbox Code Playgroud)
我还搜索了我可能对注释产生的错误,但 OrderController 中的注释看起来与其他 Controller 类中的相同。以下是 OrderController 类的示例:
@Controller
public class OrderController {
.
.
.
@GetMapping("/dispo/dispo")
@PreAuthorize("hasAuthority('ADMIN') or hasAuthority('DISPATCH')")
private String showDispoPage() {
return "/dispo/dispo";
}
@GetMapping("/dispo/orderCreate")
@PreAuthorize("hasAuthority('ADMIN') or hasAuthority('AL_SYNC_ADMIN') or hasAuthority('CLIENT_USER') or hasAuthority('DISPATCH')")
private String showCreateOrder(Model model) {
List<MdUser> …
Run Code Online (Sandbox Code Playgroud) 我有一个数据库表,其中保存文档的元数据。我现在的任务是获取包含文档类型的列表。文档类型在数据库表中并不唯一,但我当然希望它们出现在我的列表中。sql非常简单:
SELECT DISTINCT groupname, group_displayorder
FROM t_doc_metadata
ORDER BY group_displayorder;
Run Code Online (Sandbox Code Playgroud)
我了解到我可以使用投影从我的实体 DocMetadata 获取字段的子集。我解决了这个问题如下。我的实体:
@Entity
@Table(name="T_DOC_METADATA")
@Data
public class DocMetadata {
..............
@Column(nullable=false)
private String displayname;
@Column(nullable=false)
private Integer displayorder;
@Column(nullable=false)
private String groupname;
@Column(name="GROUP_DISPLAYORDER",
nullable=false)
private Integer groupDisplayorder;
@Column(name="METADATA_CHANGED_TS",
nullable=false,
columnDefinition="char")
private String metadataChangedTimestamp;
..........
}
Run Code Online (Sandbox Code Playgroud)
我的投影界面:
public interface GroupnameAndOrder {
String getGroupname();
Integer getGroupDisplayorder();
void setGroupname(String name);
void setGroupDisplayorder(int order);
}
Run Code Online (Sandbox Code Playgroud)
现在我认为通过将这些行添加到我的存储库中我会非常聪明:
@Query("select distinct d.groupname, d.groupDisplayorder from DocMetadata d order by d.groupDisplayorder")
public List<GroupnameAndOrder> findSortedGroupnames();
Run Code Online (Sandbox Code Playgroud)
遗憾的是,当迭代结果列表并调用getGroupname()时,结果为 null。 …
首先,很抱歉再次向这个话题提问.我很清楚这里有很多问题和答案.我读过其中的一些但我的问题是我仍然无法弄清楚我做错了什么.这是我的代码:
Collections.sort(hLines, new Comparator<Line>() {
@Override
public int compare(Line lhs, Line rhs) {
if ( lhs.p1.y < rhs.p1.y){
if (lhs.p2.y < rhs.p2.y)
return 1;
else
return -1;
}
if (lhs.p1.y > rhs.p1.y){
if (lhs.p2.y > rhs.p2.y)
return -1;
else
return 1;
}
else
return 0;
}
});
Collections.sort(vLines, new Comparator<Line>() {
@Override
public int compare(Line lhs, Line rhs) {
if ( lhs.p1.x < rhs.p1.x){
if (lhs.p2.x < rhs.p2.x)
return 1;
else
return -1;
}
if (lhs.p1.x > rhs.p1.x){
if (lhs.p2.x …
Run Code Online (Sandbox Code Playgroud) 我尝试了一个关于通过 Spring Boot 使用 SOAP Web 服务的教程(入门 - 使用 SOAP Web 服务)。但是在运行 Maven 构建时不会生成这些类。我对这个主题完全陌生,需要一些帮助来找出我的错误。这是我的 pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.baumgarten</groupId>
<artifactId>springwsdlconsume</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- tag::wsdl[] -->
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.12.3</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>de.baumgarten.springwsdlconsume.hello.wsdl</generatePackage>
<schemas>
<schema>
<url>http://localhost:8080/ws/my_wsdl.wsdl</url>
</schema>
</schemas>
</configuration>
</plugin>
<!-- end::wsdl[] …
Run Code Online (Sandbox Code Playgroud) 我使用 thymeleaf 视图构建了一个 Spring MVC 应用程序并遇到了以下问题。我有一个页面,它应该处理一个表单并创建一个新的实体来保存在数据库中。在我的控制器类中,我有两种方法。首先,@GetMapping 来渲染页面:
@GetMapping("/dispo/orderCreate")
private String showCreateOrder(Model model) {
List<MdUser> userList = service.getUsers();
model.addAttribute("userList", userList);
return "/dispo/orderCreate";
}
Run Code Online (Sandbox Code Playgroud)
至于我只想显示页面而不向表单添加一些操作,一切正常。模型属性“userList”正确填充了数据库中的用户。
现在我更改了视图以向表单添加一个操作和一个对象。视图的代码现在看起来像这样:
<form action="#" class="form" id="newOrderForm" th:action="@{/dispo/addOrder}" th:object="${loadOrder}" method="post">
<table class="cont-table" cellpadding="2" cellspacing="2" width="100%">
<tbody>
<tr align="left">
<th align="left" valign="top" width="110">Protokollführer:</th>
<td>
<table border="0" cellpadding="0" cellspacing="1" width="100%">
<tbody>
<tr>
<td height="30">
<select class="selectOneMenue" id="newOrderPersoDropDown" th:field="*{supervisor}">
<option>Bitte auswählen</option>
<option th:each="user : ${userList}"
th:value="user.userId"
th:text="${user.firstName}+' '+${user.lastName}"></option>
</select>
</td>
. . .
</tr>
</tbody>
</table>
<br />
<input style="width:200px" type="submit" value="Speichern" …
Run Code Online (Sandbox Code Playgroud) 有没有办法在第一个订阅者收到 MQTT 消息后从其主题中删除该消息,以便其他订阅者无法读取它?
为了弄清楚这个奇怪的问题:
我必须处理四个 JBoss 实例(我必须承认我绝对不对该架构负责)。他们是彼此的镜子。因此,它们中的每一个都运行一项订阅特定主题的作业。来自该主题的消息保留在数据库中。我必须避免的是同一条消息被保留四次。所以我的想法是在这个主题上创建一个竞争条件。第一个读取该消息的作业将其删除,以便其他作业不会收到该消息。这可能吗?
java ×4
jpa ×2
spring ×2
spring-boot ×2
collections ×1
comparator ×1
hibernate ×1
jboss ×1
mqtt ×1
mysql ×1
projection ×1
soap ×1
sorting ×1
spring-aop ×1
spring-mvc ×1
thymeleaf ×1
transactions ×1
wsdl ×1