2016-08-02 18 views
0

我使用Hibernate 4 orm並搜索我的twitter應用程序。問題是,當我開始持續鳴叫到MariaDB的表,身份證(主鍵)獲得五倍遞增:Hibernate @GeneratedValue(name = ???):ID得到5加1而不是1

2 
7 
12 
17 
22 
27 

我嘗試了所有發電類型的可用:SEQUENCE,IDENTITY,桌子和AUTO。但這些都沒有提供一個增量。我想我錯過了一些配置,否則它應該提供一個增量。
這裏是我的實體類和hibernate.cfg.xml文件:

@Entity 
@Indexed 
@Table(name="tweets_table") 
public class TweetPOJO implements Serializable{ 

private static final long serialVersionUID = 1123211L; 

@Id 
@GeneratedValue (???) 
@Column(name = "raw_id") 
private int raw_id; 

@Column(name = "tweet_id") 
private String tweet_id; 


@DateBridge(resolution=Resolution.DAY) 
@Column(name = "posted_time") 
private String timestamp; 

@Field(index = Index.YES, analyze = Analyze.YES, store = Store.NO) 
@Column(name = "cleaned_text") 
private String tweet_text; 


@Column(name = "hashtags") 
@Field(index=Index.YES, analyze=Analyze.NO, store=Store.YES) 
private String hashtags; 

@Column(name = "media_url") 
private String media_url; 

@Column(name = "media_text") 
private String media_text; 

@Column(name = "media_type") 
private String media_type; 

@Column(name = "location") 
private String location; 

... 
... 
public void setUser_frind_count(int user_frind_count) { 
    this.user_frind_count = user_frind_count; 
} 

@Override 
public String toString() { 
    return tweet_id+" : "+tweet_text; 
} 

} 

這裏是hibernate.cfg.xml中

<?xml version="1.0" encoding="utf-8"?> 
<!DOCTYPE hibernate-configuration SYSTEM "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> 

<hibernate-configuration> 
<session-factory> 

    <property name="hibernate.bytecode.use_reflection_optimizer"> true </property> 
    <property name="hibernate.dialect"> org.hibernate.dialect.MySQLDialect </property> 
    <property name="hibernate.connection.driver_class"> com.mysql.jdbc.Driver </property> 

    <!-- Assume test is the database name --> 
    <property name="hibernate.connection.url"> jdbc:mysql://*******/clouddata </property> 
    <property name="hibernate.connection.username"> root </property> 
    <property name="hibernate.connection.password"> qwe123 </property> 


    <property name="connection.pool_size"> 1 </property> 
    <property name="hibernate.search.default.directory_provider"> filesystem </property> 

    <property name="hibernate.search.default.indexBase"> E:\lucene_index </property> 
    <!-- 
    whether the schema will be created or just updated, every time the sessionFactory is created. 
    This is configured in the hibernate.hbm2ddl.auto property, which is set to update. So the schema 
    is only updated. If this property is set to create, then every time we run our application, the 
    schema will be re-created, thus deleting previous data. 
    --> 
    <property name="hibernate.hbm2ddl.auto">update</property> 
    <mapping class="twitter_crawling_modul.TweetPOJO"/> 
</session-factory> 

+0

實際操作對象的代碼丟失了,很可能是culpr它:這通常發生在持久化對象之前更新對象幾次,捕獲一些異常等。這對錶格來說不是問題(鍵不必是連續的,並且在64位密鑰空間中它即使你跳過一堆也需要一段時間)。這可能是你的代碼中的一個嚴重問題。 –

+0

'SHOW VARIABLES like'auto_inc%';' –

+0

@NorbertvanNobelen我該如何解決這個問題?你能提出一些建議嗎? – Humoyun

回答

2

你可以嘗試使用序列發生器

@SequenceGenerator(name = "seq", sequenceName = "seq_name", allocationSize = 1) 
@GeneratedValue (strategy = GenerationType.SEQUENCE, generator = "seq") 
相關問題