【发布时间】:2012-04-19 11:53:36
【问题描述】:
Q1.:在数据库中应用序列 ID 与使用
有什么区别答。
CREATE TABLE Person
(
id long NOT NULL AUTO_INCREMENT
...
PRIMARY KEY (id)
)
对比
B.
@Entity
public class Person {
@Id
@TableGenerator(name="TABLE_GEN", table="SEQUENCE_TABLE", pkColumnName="SEQ_NAME",
valueColumnName="SEQ_COUNT", pkColumnValue="PERSON_SEQ")
@GeneratedValue(strategy=GenerationType.TABLE, generator="TABLE_GEN")
private long id;
...
}
我的系统高度并发。由于我的 DB 是 Microsoft SQL server,我认为它不支持@SequenceGenerator,所以我必须留在@TableGenerator,这很容易出现并发问题。
Q2. 此链接 (http://en.wikibooks.org/wiki/Java_Persistence/Identity_and_Sequencing#Advanced_Sequencing) 表明 B 可能会遇到并发问题,但我不理解建议的解决方案。如果有人能向我解释如何避免 B 的并发问题,我将不胜感激。这是他们解决方案的 sn-p:
If a large sequence pre-allocation size is used this becomes less of an issue, because the sequence table is rarely accessed.
Q2.1:我们在这里讨论的分配大小是多少?我应该使用allocationSize=10 还是allocationSize=100?
Some JPA providers use a separate (non-JTA) connection to allocate the sequence ids in, avoiding or limiting this issue. In this case, if you use a JTA data-source connection, it is important to also include a non-JTA data-source connection in your persistence.xml.
Q2.2:我使用 EclipseLink 作为我的提供者;我必须按照上面的建议去做吗?
Q3.如果B遇到并发问题,A是否也会遇到同样的问题?
【问题讨论】:
标签: java sql sql-server jpa eclipselink