我正在尝试使用Hibernate作为提供程序为我的Maven项目设置JPA.
项目结构
??? META-INF
? ??? persistence.xml
??? src
| ??? main
| | ??? java
| | ??? model
| | | ??? Instance.java
| | ??? App.java
| ??? test
| ??? java
| ??? model
| ??? AppTest.java
??? pom.xml
Run Code Online (Sandbox Code Playgroud)
persistence.xml的内容
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" version="2.1">
<persistence-unit name="testjpa" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>it.vitrociset.model.Instance</class>
<properties>
<property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/aquasystem"/>
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
<property name="hibernate.connection.username" value="username"/>
<property name="hibernate.connection.password" value="password"/>
</properties>
</persistence-unit>
</persistence>
Run Code Online (Sandbox Code Playgroud)
Instance.java的内容
package model;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public …Run Code Online (Sandbox Code Playgroud) 我想为一组玩家建模数据库实体.每位玩家应该:
实现这样一个实体的最佳方式是什么(关系数据库和非关系数据库对我来说都没问题)?
最简单的解决方案当然是为每个角色保留一个不同的表.我也找到了这个答案,这很好但是7岁,可能已经过时了.其他想法?
这是一个示例数据集:
"name": "name1"
"role": "attack"
"strength": 10
"constitution": 5
"name": "name2"
"role": "attack"
"strength": 7
"constitution": 7
"name": "name3"
"role": "defense"
"health": 8
"resistence": 8
"name": "name4"
"role": "defense"
"health": 10
"resistence": 10
"name": "name5"
"role": "support"
"mana": 4
"willpower": 3
Run Code Online (Sandbox Code Playgroud) 我有一个表单,其notes字段以 textarea 为界。
this.form = this.formBuilder.group({});
this.form.addControl('notes', new FormControl(''));
Run Code Online (Sandbox Code Playgroud)
该模板autoresize附有一个指令。
<textarea formControlName="notes" autosize></textarea>
Run Code Online (Sandbox Code Playgroud)
每次用户更改其内容时,这样的指令都会调整 textarea 的高度。
@HostListener('input')
public onChange(textArea: HTMLTextAreaElement): void {
const textarea = this.element.nativeElement.querySelector('textarea');
this.renderer.setStyle(textarea, 'overflow', 'hidden');
this.renderer.setStyle(textarea, 'height', 'auto');
this.renderer.setStyle(textarea, 'height', `${textarea.scrollHeight}px`);
}
Run Code Online (Sandbox Code Playgroud)
但是,当我以编程方式更改 FormControl 的值时,input不会触发该事件,并且不会相应地调整 textarea 的大小。
this.form.controls['notes'].setValue('a new value'); // not firing events
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我有带有复合驼峰式名称的 Java 实体,例如EmployeeProject.
我需要将这些实体映射到具有蛇形名称的表上,例如 ,employee_project而不是 Quarkus/Panache 使用的默认值,例如employeeproject。
我知道我可以设置自定义表名称,@Entity(name = "employee_project")但我想知道是否有某种应用程序属性可以为我做同样的工作。