2012-01-06 23 views
8

Database:JPA tabella "sequenza" non esiste

user_account 
id(pk) 
email 
password 
... 

user_detail 
id(pk fk) 
name_first 
name_last 
... 

Entity

@Entity 
@Table(name="user_account")  
@SecondaryTable(name="user_detail", [email protected]()) 
public class UserAccount implements Serializable{ 
    private static final long serialVersionUID = -2606506548742732094L; 

    @Id 
    @GeneratedValue(strategy=GenerationType.AUTO) 
    private Integer id; 
    private String email; 
    private String password; 
    private String tab; 
    private String shortcut; 
    private String setting; 
    private Integer role; 

    @Column(table="user_detail", name="name_first") 
    private String nameFirst; 
    @Column(table="user_detail", name="name_last") 
    private String nameLast; 
    @Column(table="user_detail") 
    private String occupation; 
    @Column(table="user_detail") 
    @Temporal(TemporalType.DATE) 
    private Date birth; 
    .... 
} 

azione

try{ 
     EntityTransaction transaction = em.getTransaction(); 
     transaction.begin(); 
     em.persist(currentUser); 

     transaction.commit(); 
    } catch (Exception e){ 
    } 

Errore

INFO: [EL Warning]: 2012-01-06 18:45:46.77--ClientSession(17472935)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Table 'mazedb.sequence' doesn't exist Error Code: 1146 Call: UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ? bind => [2 parameters bound] Query: DataModifyQuery(name="SEQUENCE" sql="UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?")

INFO: ERROR: Internal Exception: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Table 'mazedb.sequence' doesn't exist Error Code: 1146 Call: UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ? bind => [2 parameters bound] Query: DataModifyQuery(name="SEQUENCE" sql="UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?")

ho provato il contrario, avere due entità diverse unite da @PrimaryKeyJoinColumn ma ho ottenuto lo stesso errore.

+0

Bene, il messaggio dice che è necessario avere una tabella di sequenze. Perché non lo crei? –

+0

Ma perché avrei bisogno di questo tavolo se non dovessi esserci? – TGM

risposta

14

Se EclipseLink tenta di accedere a questa tabella, significa che dovrebbe essere lì. GenerationType.AUTO significa che EclipseLink sceglie il tipo di generazione più appropriato per il tuo database (MySQL). In questo caso, la scelta è di utilizzare un generatore basato su tabella, che ha bisogno di una tabella. Vedi http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Entities/Ids/GeneratedValue.

Se non si desidera utilizzare questa strategia, scegline un'altra.

+0

Il link indicato è morto. –

5

Non avevo mai avuto questo errore prima nonostante facesse questo genere di cose un centinaio di volte. Ho trovato questo errore era perché avevo una proprietà Hibernate per la creazione di tabelle nel persistence.xml ma stavo usando EclipseLink:

Era:

<property name="hibernate.hbm2ddl.auto" value="create"/> 

ho cambiato a quanto segue per correggere l'errore:

<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/> 
    <!-- or just value="create-tables" --> 
+0

Ha funzionato per me, anche se non avevo la prima proprietà definita in persistence.xml. L'aggiunta della proprietà suggeriva ha portato via l'eccezione. –

-1

Nel file di configurazione, la riga org.hibernate.dialect.oracle10gdialect può essere dimenticata. Infatti, dovrebbe essere org.hibernate.dialect.mysqldialect.

Problemi correlati