我在MySQL 5.6中更改lower_case_table_names变量值时遇到问题...我在Windows xampp上更改了lower_case_table_names = 2的值时所做的全部内容.
我的Windows 7上的默认值为"1".我想把它切换为'2'.
试过几种方式,我做的是:
现在,当我读到"SELECT @@ lower_case_table_names"时,它仍然显示为1,而我的数据库表现得像1 ...
有任何想法吗?
当我的应用程序出现乐观并发问题时,我的应用程序中抛出StaleObjectStateException而不是OptimisticLockException(因为我读到我应该期待这个).无需发布代码,因为它是最基本的并发问题 - 时间戳列中的错误版本.
我怎么会得到OptimisticLockException,而不是另一个?
首先,我读过Hibernate - One table with multiple entity? .
但是,我想将两个实体映射到同一个表,但我希望它们都是实体,我可以从中进行选择。我的意思是:
所以它是实体之间的 1:1 关系,但在 DB 中仍然是 1 个表。
如果我使用上述链接中建议的解决方案(组件关键字)来执行此操作,则无法直接查询地址(我可以通过 Person 实体访问它)。我希望能够做到
session.createCriteria(Adres.class)
Run Code Online (Sandbox Code Playgroud)
我怎么做?
更新:我在地址映射中尝试了实体之间的一对一关联:
<one-to-one name="Person " class="model_mapowanie_xml.Person "/>
Run Code Online (Sandbox Code Playgroud)
和个人映射:
<one-to-one name="Address" class="model_mapowanie_xml.Address "/>
Run Code Online (Sandbox Code Playgroud)
两个类都有引用另一个类的字段。选择记录可以很好地解决这个问题。但是,如何在一个交易中使用两个实体添加一条记录?(Id 是数据库生成的)
Address ad = new Address();
ad.setProperty("Sydney");
Person p = new Person();
p.setProperty("John");
p.setAddress(ad);
session.save(p);
Run Code Online (Sandbox Code Playgroud)
并且只保存了 Person 部分,address 属性保持为空。
我想将外部策略生成器用于我班级中的一个关键属性.最简单的方法如下所示:http: //blog.eyallupu.com/2011/01/hibernatejpa-identity-generators.html 或 http://www.coderanch.com/t/219256/ORM/databases/HBM-Annotation -Foreign-Generator 或 http://www.mkyong.com/hibernate/hibernate-one-to-one-relationship-example-annotation/
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.*;
import org.hibernate.annotations.GenericGenerator;
...
...
...
@GenericGenerator(
name = "myForeignGenerator",
strategy = "foreign",
parameters = @Parameter(name = "property", value = "osoba"))
@Id
@GeneratedValue(generator = "myForeignGenerator")
@Column(name = "IdPracownik", unique = true, nullable = false)
public int getIdPracownik() {
return this.idPracownik;
}
Run Code Online (Sandbox Code Playgroud)
和Eclipse显示错误:
"类型不匹配:无法从参数转换为注释",下划线"@Parameter"注释.
这是为什么?
hibernate ×3
annotations ×1
concurrency ×1
exception ×1
foreign-keys ×1
mysql ×1
one-to-one ×1
sql ×1