Ошибка при попытке сопоставить (сохранить) мою базу данных - PullRequest
1 голос
/ 17 июня 2011

Я пытаюсь отобразить свою базу данных (базу данных jira) с использованием JPA / Hibernate.но при этом возникает ошибка !! (я попробовал ту же конфигурацию в другой базе данных, и она сработала) Мои файлы конфигурации:

persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
    xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="JIRAKPIPU" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <class>DTOJIRA.Portalpage</class>
        <class>DTOJIRA.QrtzFiredTriggers</class>
        <class>DTOJIRA.Jiraworkflows</class>
        <class>DTOJIRA.Externalgadget</class>
        <class>DTOJIRA.OsHistorystepPrev</class>
        <class>DTOJIRA.Versioncontrol</class>
        <class>DTOJIRA.CwdApplicationAddress</class>
        <class>DTOJIRA.Oauthspconsumer</class>
        <class>DTOJIRA.Label</class>
        <class>DTOJIRA.Propertydata</class>
        <class>DTOJIRA.ExternalEntities</class>
        <class>DTOJIRA.Changeitem</class>
        <class>DTOJIRA.Upgradehistory</class>
        <class>DTOJIRA.Favouriteassociations</class>
        <class>DTOJIRA.Jiraaction</class>
        <class>DTOJIRA.Issuestatus</class>
        <class>DTOJIRA.Priority</class>
        <class>DTOJIRA.Serviceconfig</class>
        <class>DTOJIRA.QrtzJobDetails</class>
        <class>DTOJIRA.Permissionscheme</class>
        <class>DTOJIRA.Userhistoryitem</class>
        <class>DTOJIRA.Oauthconsumertoken</class>
        <class>DTOJIRA.QrtzJobListeners</class>
        <class>DTOJIRA.Fieldlayoutscheme</class>
        <class>DTOJIRA.Jiraeventtype</class>
        <class>DTOJIRA.Genericconfiguration</class>
        <class>DTOJIRA.Searchrequest</class>
        <class>DTOJIRA.Configurationcontext</class>
        <class>DTOJIRA.Changegroup</class>
        <class>DTOJIRA.Customfieldoption</class>
        <class>DTOJIRA.Customfield</class>
        <class>DTOJIRA.OsCurrentstepPrev</class>
        <class>DTOJIRA.Userassociation</class>
        <class>DTOJIRA.Remembermetoken</class>
        <class>DTOJIRA.Userbase</class>
        <class>DTOJIRA.Fieldconfigscheme</class>
        <class>DTOJIRA.Jiraissue</class>
        <class>DTOJIRA.CwdDirectoryOperation</class>
        <class>DTOJIRA.Issuetypescreenscheme</class>
        <class>DTOJIRA.Gadgetuserpreference</class>
        <class>DTOJIRA.Filtersubscription</class>
        <class>DTOJIRA.Optionconfiguration</class>
        <class>DTOJIRA.Projectroleactor</class>
        <class>DTOJIRA.Fieldscreen</class>
        <class>DTOJIRA.Propertydate</class>
        <class>DTOJIRA.Oauthsptoken</class>
        <class>DTOJIRA.QrtzCronTriggers</class>
        <class>DTOJIRA.Schemeissuesecuritylevels</class>
        <class>DTOJIRA.Upgradeversionhistory</class>
        <class>DTOJIRA.Projectversion</class>
        <class>DTOJIRA.CwdDirectory</class>
        <class>DTOJIRA.Fieldscreenlayoutitem</class>
        <class>DTOJIRA.Fieldscreenschemeitem</class>
        <class>DTOJIRA.Notificationscheme</class>
        <class>DTOJIRA.Issuelinktype</class>
        <class>DTOJIRA.OsWfentry</class>
        <class>DTOJIRA.Fieldscreenscheme</class>
        <class>DTOJIRA.Notification</class>
        <class>DTOJIRA.Issuesecurityscheme</class>
        <class>DTOJIRA.Schemeissuesecurities</class>
        <class>DTOJIRA.Jiradraftworkflows</class>
        <class>DTOJIRA.CwdApplication</class>
        <class>DTOJIRA.Jiraperms</class>
        <class>DTOJIRA.QrtzSimpleTriggers</class>
        <class>DTOJIRA.Fieldscreentab</class>
        <class>DTOJIRA.QrtzTriggers</class>
        <class>DTOJIRA.Component</class>
        <class>DTOJIRA.Issuelink</class>
        <class>DTOJIRA.Trustedapp</class>
        <class>DTOJIRA.Fileattachment</class>
        <class>DTOJIRA.Propertydecimal</class>
        <class>DTOJIRA.Propertystring</class>
        <class>DTOJIRA.Avatar</class>
        <class>DTOJIRA.Project</class>
        <class>DTOJIRA.CwdUser</class>
        <class>DTOJIRA.Membershipbase</class>
        <class>DTOJIRA.CwdDirectoryAttribute</class>
        <class>DTOJIRA.Workflowschemeentity</class>
        <class>DTOJIRA.Notificationinstance</class>
        <class>DTOJIRA.Fieldconfigschemeissuetype</class>
        <class>DTOJIRA.Schemepermissions</class>
        <class>DTOJIRA.Projectrole</class>
        <class>DTOJIRA.Issuetype</class>
        <class>DTOJIRA.Columnlayoutitem</class>
        <class>DTOJIRA.Groupbase</class>
        <class>DTOJIRA.Columnlayout</class>
        <class>DTOJIRA.Mailserver</class>
        <class>DTOJIRA.Sharepermissions</class>
        <class>DTOJIRA.Propertyentry</class>
        <class>DTOJIRA.Oauthconsumer</class>
        <class>DTOJIRA.CwdMembership</class>
        <class>DTOJIRA.SequenceValueItem</class>
        <class>DTOJIRA.TrackbackPing</class>
        <class>DTOJIRA.Fieldlayout</class>
        <class>DTOJIRA.Customfieldvalue</class>
        <class>DTOJIRA.Propertynumber</class>
        <class>DTOJIRA.Workflowscheme</class>
        <class>DTOJIRA.Listenerconfig</class>
        <class>DTOJIRA.QrtzTriggerListeners</class>
        <class>DTOJIRA.Portletconfiguration</class>
        <class>DTOJIRA.Projectcategory</class>
        <class>DTOJIRA.Fieldlayoutitem</class>
        <class>DTOJIRA.Pluginversion</class>
        <class>DTOJIRA.OsHistorystep</class>
        <class>DTOJIRA.CwdGroup</class>
        <class>DTOJIRA.CwdGroupAttributes</class>
        <class>DTOJIRA.Fieldlayoutschemeassociation</class>
        <class>DTOJIRA.Issuetypescreenschemeentity</class>
        <class>DTOJIRA.Fieldconfiguration</class>
        <class>DTOJIRA.Fieldlayoutschemeentity</class>
        <class>DTOJIRA.Propertytext</class>
        <class>DTOJIRA.OsCurrentstep</class>
        <class>DTOJIRA.Resolution</class>
        <class>DTOJIRA.QrtzCalendars</class>
        <class>DTOJIRA.Worklog</class>
        <class>DTOJIRA.Nodeassociation</class>
        <class>DTOJIRA.CwdUserAttributes</class>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        <properties>
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/jiradb" />
            <property name="javax.persistence.jdbc.password" value="root" />
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
            <property name="javax.persistence.jdbc.user" value="root" />
        </properties>
    </persistence-unit>
</persistence>

**hibernate.cfg.xml**
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/jiradb</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password">root</property>
    </session-factory>
</hibernate-configuration>

Мой класс Прочитано:

public class JiraissueRead {
    EntityManagerFactory emf = Persistence
            .createEntityManagerFactory("JIRAKPIPU");
    EntityManager em = emf.createEntityManager();

    public JiraissueRead() {
    }

    public Jiraissue findKpi(Integer id) {
        System.out.println("ttttttttttttttttttttttttttttttttt");

        try {

            EntityTransaction entr = em.getTransaction();
            System.out.println("debut 1");
            entr.begin();
            entr.commit();
            System.out.println("debut 2");
            Jiraissue j = em.find(Jiraissue.class, id);
            return j;
        } catch (Exception e) {
            System.out.println(e.getMessage());
        } finally {
            em.close();
        }
        return null;
    }
}

MAIN:

public static void main(String[] args) {
    // TODO code application logic here
    JiraissueRead jiraissue = new JiraissueRead();
    System.out.println("_______________");
    System.out.println(jiraissue.findKpi(10000));

}

Ошибка

17 juin 2011 17:39:12 org.hibernate.cfg.annotations.QueryBinder bindQuery
INFO: Binding Named query: CwdUserAttributes.findById => SELECT c FROM CwdUserAttributes c WHERE c.id = :id
17 juin 2011 17:39:12 org.hibernate.cfg.annotations.QueryBinder bindQuery
INFO: Binding Named query: CwdUserAttributes.findByUserId => SELECT c FROM   CwdUserAttributes c WHERE c.userId = :userId
17 juin 2011 17:39:12 org.hibernate.cfg.annotations.QueryBinder bindQuery
INFO: Binding Named query: CwdUserAttributes.findByDirectoryId => SELECT c FROM    CwdUserAttributes c WHERE c.directoryId = :directoryId
17 juin 2011 17:39:12 org.hibernate.cfg.annotations.QueryBinder bindQuery
INFO: Binding Named query: CwdUserAttributes.findByAttributeName => SELECT c FROM CwdUserAttributes c WHERE c.attributeName = :attributeName
 17 juin 2011 17:39:12 org.hibernate.cfg.annotations.QueryBinder bindQuery
 INFO: Binding Named query: CwdUserAttributes.findByAttributeValue => SELECT c FROM   CwdUserAttributes c WHERE c.attributeValue = :attributeValue
 17 juin 2011 17:39:12 org.hibernate.cfg.annotations.QueryBinder bindQuery
 INFO: Binding Named query: CwdUserAttributes.findByLowerAttributeValue => SELECT c FROM CwdUserAttributes c WHERE c.lowerAttributeValue = :lowerAttributeValue
 17 juin 2011 17:39:12 org.hibernate.cfg.annotations.EntityBinder bindTable
 INFO: Bind entity DTOJIRA.CwdUserAttributes on table cwd_user_attributes
 17 juin 2011 17:39:12 org.hibernate.cfg.AnnotationConfiguration secondPassCompile
 INFO: Hibernate Validator not found: ignoring
  17 juin 2011 17:39:12 org.hibernate.connection.UserSuppliedConnectionProvider configure
 ATTENTION: No connection properties specified - the user must supply JDBC connections
 Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: J  IRAKPIPU] Unable to build EntityManagerFactory
 at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:677)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory  (HibernatePersistence.java:126)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
at DAOJIRA.JiraissueRead.<init>(JiraissueRead.java:16)
at DAOJIRA.Main.main(Main.java:18)
 Caused by: org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
at org.hibernate.dialect.DialectFactory.determineDialect(DialectFactory.java:57)
at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:39)
at org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:426)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:128)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory   (AnnotationConfiguration.java:859)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
... 5 more
Java Result: 1

После того, как я добавил hibernate.dialect в свой файл persistence.xml и ошибка изменилась, знайте, что ошибка (ошибка слишком длинная):

INFO: Binding Named query: Nodeassociation.findAll => SELECT n FROM Nodeassociation n
18 juin 2011 09:49:46 org.hibernate.cfg.annotations.QueryBinder bindQuery
INFO: Binding Named query: Nodeassociation.findBySourceNodeId => SELECT n FROM     Nodeassociation n WHERE n.nodeassociationPK.sourceNodeId = :sourceNodeId
18 juin 2011 09:49:46 org.hibernate.cfg.annotations.QueryBinder bindQuery
INFO: Binding Named query: Nodeassociation.findBySourceNodeEntity => SELECT n FROM      Nodeassociation n WHERE n.nodeassociationPK.sourceNodeEntity = :sourceNodeEntity
18 juin 2011 09:49:46 org.hibernate.cfg.annotations.QueryBinder bindQuery
INFO: Binding Named query: Nodeassociation.findBySinkNodeId => SELECT n FROM Nodeassociation n WHERE n.nodeassociationPK.sinkNodeId = :sinkNodeId
18 juin 2011 09:49:46 org.hibernate.cfg.annotations.QueryBinder bindQuery
INFO: Binding Named query: Nodeassociation.findBySinkNodeEntity => SELECT n FROM    Nodeassociation n WHERE n.nodeassociationPK.sinkNodeEntity = :sinkNodeEntity
18 juin 2011 09:49:46 org.hibernate.cfg.annotations.QueryBinder bindQuery
INFO: Binding Named query: Nodeassociation.findByAssociationType => SELECT n FROM Nodeassociation n WHERE n.nodeassociationPK.associationType = :associationType
18 juin 2011 09:49:46 org.hibernate.cfg.annotations.QueryBinder bindQuery
INFO: Binding Named query: Nodeassociation.findBySequence => SELECT n FROM   Nodeassociation n WHERE n.sequence = :sequence
18 juin 2011 09:49:46 org.hibernate.cfg.annotations.EntityBinder bindTable
INFO: Bind entity DTOJIRA.Nodeassociation on table nodeassociation
18 juin 2011 09:49:46 org.hibernate.cfg.AnnotationBinder bindClass
INFO: Binding entity from annotated class: DTOJIRA.CwdUserAttributes
18 juin 2011 09:49:46 org.hibernate.cfg.annotations.QueryBinder bindQuery
INFO: Binding Named query: CwdUserAttributes.findAll => SELECT c FROM CwdUserAttributes c
18 juin 2011 09:49:46 org.hibernate.cfg.annotations.QueryBinder bindQuery
INFO: Binding Named query: CwdUserAttributes.findById => SELECT c FROM CwdUserAttributes c WHERE c.id = :id
18 juin 2011 09:49:46 org.hibernate.cfg.annotations.QueryBinder bindQuery
INFO: Binding Named query: CwdUserAttributes.findByUserId => SELECT c FROM  CwdUserAttributes c WHERE c.userId = :userId
 18 juin 2011 09:49:46 org.hibernate.cfg.annotations.QueryBinder bindQuery
INFO: Binding Named query: CwdUserAttributes.findByDirectoryId => SELECT c FROM    CwdUserAttributes c WHERE c.directoryId = :directoryId
18 juin 2011 09:49:46 org.hibernate.cfg.annotations.QueryBinder bindQuery
INFO: Binding Named query: CwdUserAttributes.findByAttributeName => SELECT c FROM  CwdUserAttributes c WHERE c.attributeName = :attributeName
18 juin 2011 09:49:46 org.hibernate.cfg.annotations.QueryBinder bindQuery
INFO: Binding Named query: CwdUserAttributes.findByAttributeValue => SELECT c FROM    CwdUserAttributes c WHERE c.attributeValue = :attributeValue
18 juin 2011 09:49:46 org.hibernate.cfg.annotations.QueryBinder bindQuery
INFO: Binding Named query: CwdUserAttributes.findByLowerAttributeValue => SELECT c FROM CwdUserAttributes c WHERE c.lowerAttributeValue = :lowerAttributeValue
18 juin 2011 09:49:46 org.hibernate.cfg.annotations.EntityBinder bindTable
INFO: Bind entity DTOJIRA.CwdUserAttributes on table cwd_user_attributes
18 juin 2011 09:49:46 org.hibernate.cfg.AnnotationConfiguration secondPassCompile
INFO: Hibernate Validator not found: ignoring
18 juin 2011 09:49:47 org.hibernate.connection.UserSuppliedConnectionProvider configure
ATTENTION: No connection properties specified - the user must supply JDBC connections
juin 2011 09:49:47 org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.MySQLDialect
18 juin 2011 09:49:47 org.hibernate.transaction.TransactionFactoryFactory       buildTransactionFactory
INFO: Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
18 juin 2011 09:49:47 org.hibernate.transaction.TransactionManagerLookupFactory  getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or    transactional second-level cache is not recommended)
18 juin 2011 09:49:47 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
18 juin 2011 09:49:47 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
18 juin 2011 09:49:47 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: disabled
18 juin 2011 09:49:47 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): disabled
18 juin 2011 09:49:47 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
18 juin 2011 09:49:47 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Maximum outer join fetch depth: 2
18 juin 2011 09:49:47 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
18 juin 2011 09:49:47 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
18 juin 2011 09:49:47 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
18 juin 2011 09:49:47 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
18 juin 2011 09:49:47 org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
18 juin 2011 09:49:47 org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
18 juin 2011 09:49:47 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
18 juin 2011 09:49:47 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: enabled
18 juin 2011 09:49:47 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
18 juin 2011 09:49:47 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
18 juin 2011 09:49:47 org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.NoCacheProvider
18 juin 2011 09:49:47 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
18 juin 2011 09:49:47 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
18 juin 2011 09:49:47 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
18 juin 2011 09:49:47 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
18 juin 2011 09:49:47 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
18 juin 2011 09:49:47 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
18 juin 2011 09:49:47 org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
18 juin 2011 09:49:47 org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
 _______________
 ttttttttttttttttttttttttttttttttt
debut 1
The user must supply a JDBC connection
errrrrs
++++++++++null
BUILD SUCCESSFUL (total time: 5 seconds)

1 Ответ

3 голосов
/ 17 июня 2011

Диалект, который будет использоваться Hibernate EntityManager при использовании в качестве поставщика JPA, может быть настроен как свойство в файле persistence.xml следующим образом:

<persistence-unit>
  <properties>
      ...
      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
      ...
  </properties>
</persistence-unit>

Настройка Hibernate для использования в качествеПоставщик JPA 2.0.

Если исходить из документации Hibernate EntityManager , файл hibernate-cfg.xml не требуется в среде, где используется JPA.Все свойства могут быть указаны в файле persistence.xml, и они могут также включать свойства, которые являются родными для Hibernate.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...