Visualizzazione dei risultati da 1 a 2 su 2

Discussione: [java] hibernate

  1. #1
    Utente di HTML.it
    Registrato dal
    Oct 2007
    Messaggi
    331

    [java] hibernate

    Ciao a tutti, sto provando ad utilizzare hibernate in una web application java ma sto avendo dei problemi sul file di configurazione.

    Sul log del server mi trovo questo log:

    ERROR http-bio-8080-exec-186 org.hibernate.util.XMLHelper ? Error parsing XML: /hibernate.cfg.xml(2) Documento non valido: nessuna grammatica trovata.
    ERROR http-bio-8080-exec-186 org.hibernate.util.XMLHelper ? Error parsing XML: /hibernate.cfg.xml(2) L'elemento radice "hibernate-configuration" del documento deve corrispondere alla radice DOCTYPE "null".

    e il file di configurazione è questo

    codice:
    <?xml version="1.0" encoding="utf-8"?>
    <hibernate-configuration>
        <session-factory>
            <property name="connection.driver_class">
                com.mysql.jdbc.Driver
            </property>
            <property name="connection.url">
                jdbc:mysql://localhost:3306/test
            </property>
            <property name="connection.username">user</property>
            <property name="connection.password">pssw</property>
            <property name="connection.pool_size">1</property>
            <property name="dialect">
                org.hibernate.dialect.MySQLDialect
            </property>
            <property name="current_session_context_class">thread</property>
            <property name="cache.provider_class">
                org.hibernate.cache.NoCacheProvider
            </property>
            <property name="show_sql">true</property>
            <property name="hbm2ddl.auto">update</property>
     
         </session-factory>
    </hibernate-configuration>
    Qualcuno sa dirmi qualcosa?

    Ciao, grazie

  2. #2
    Moderatore di Programmazione L'avatar di LeleFT
    Registrato dal
    Jun 2003
    Messaggi
    17,320
    Tra il preambolo e l'elemeno radice va indicato il DOCTYPE:

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

    Ciao.
    "Perchè spendere anche solo 5 dollari per un S.O., quando posso averne uno gratis e spendere quei 5 dollari per 5 bottiglie di birra?" [Jon "maddog" Hall]
    Fatti non foste a viver come bruti, ma per seguir virtute e canoscenza

  3. #3
    Utente di HTML.it
    Registrato dal
    Oct 2007
    Messaggi
    331

    grazie

    Quel problema è stato risolto, ora ne ho un altro.

    Ho creato la seguente classe

    codice:
    package it.telecomitalia.db.util;
    
    
    import it.telecomitalia.util.MyLogger;
    
    
    import org.hibernate.SessionFactory;
    import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
    import org.hibernate.cfg.Configuration;
    import org.hibernate.service.ServiceRegistry;
    
    
    public class HibernateUtil {
     
        private static SessionFactory sessionFactory;
        private static ServiceRegistry serviceRegistry;
        
        private static SessionFactory createSessionFactory() {
            MyLogger.printLogDebug("HibernateUtil -> createSessionFactory START!");
            Configuration configuration = new Configuration();
            MyLogger.printLogDebug("HibernateUtil -> createSessionFactory 1");
            configuration.configure();
            MyLogger.printLogDebug("HibernateUtil -> createSessionFactory 2");
            serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
            MyLogger.printLogDebug("HibernateUtil -> createSessionFactory 3");
            sessionFactory = configuration.buildSessionFactory(serviceRegistry);
            MyLogger.printLogDebug("HibernateUtil -> createSessionFactory 4");
            return sessionFactory;
        }
     
        public static SessionFactory getSessionFactory() {
            MyLogger.printLogDebug("HibernateUtil -> getSessionFactory START!");
            if (sessionFactory == null) createSessionFactory();
            return sessionFactory;
        }
    }
    e sembra che su questo metodo: configuration.buildSessionFactory(serviceRegistry)

    ci sia qualche problema.
    I log sono i seguenti:

    codice:
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.annotations.EntityBinder ? Import with entity name Contact
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.annotations.EntityBinder ? Bind entity it.telecomitalia.strutsexample.model.Contact on table Contacts
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.Ejb3Column ? Binding column: Ejb3Column{table=org.hibernate.mapping.Table(Contacts), mappingColumn=id, insertable=true, updatable=true, unique=false}
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.annotations.PropertyBinder ? MetadataSourceProcessor property id with lazy=false
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.AbstractPropertyHolder ? Attempting to locate auto-apply AttributeConverter for property [it.telecomitalia.strutsexample.model.Contact:id]
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.annotations.SimpleValueBinder ? building SimpleValue for id
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.annotations.PropertyBinder ? Building property id
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.Ejb3Column ? Binding column: Ejb3Column{table=org.hibernate.mapping.Table(Contacts), mappingColumn=birthdate, insertable=true, updatable=true, unique=false}
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.annotations.PropertyBinder ? MetadataSourceProcessor property birthDate with lazy=false
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.AbstractPropertyHolder ? Attempting to locate auto-apply AttributeConverter for property [it.telecomitalia.strutsexample.model.Contact:birthDate]
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.annotations.SimpleValueBinder ? building SimpleValue for birthDate
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.annotations.PropertyBinder ? Building property birthDate
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.Ejb3Column ? Binding column: Ejb3Column{table=org.hibernate.mapping.Table(Contacts), mappingColumn=cell_no, insertable=true, updatable=true, unique=false}
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.annotations.PropertyBinder ? MetadataSourceProcessor property cellNo with lazy=false
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.AbstractPropertyHolder ? Attempting to locate auto-apply AttributeConverter for property [it.telecomitalia.strutsexample.model.Contact:cellNo]
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.annotations.SimpleValueBinder ? building SimpleValue for cellNo
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.annotations.PropertyBinder ? Building property cellNo
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.Ejb3Column ? Binding column: Ejb3Column{table=org.hibernate.mapping.Table(Contacts), mappingColumn=created, insertable=true, updatable=true, unique=false}
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.annotations.PropertyBinder ? MetadataSourceProcessor property created with lazy=false
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.AbstractPropertyHolder ? Attempting to locate auto-apply AttributeConverter for property [it.telecomitalia.strutsexample.model.Contact:created]
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.annotations.SimpleValueBinder ? building SimpleValue for created
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.annotations.PropertyBinder ? Building property created
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.Ejb3Column ? Binding column: Ejb3Column{table=org.hibernate.mapping.Table(Contacts), mappingColumn=email_id, insertable=true, updatable=true, unique=false}
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.annotations.PropertyBinder ? MetadataSourceProcessor property emailId with lazy=false
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.AbstractPropertyHolder ? Attempting to locate auto-apply AttributeConverter for property [it.telecomitalia.strutsexample.model.Contact:emailId]
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.annotations.SimpleValueBinder ? building SimpleValue for emailId
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.annotations.PropertyBinder ? Building property emailId
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.Ejb3Column ? Binding column: Ejb3Column{table=org.hibernate.mapping.Table(Contacts), mappingColumn=firstname, insertable=true, updatable=true, unique=false}
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.annotations.PropertyBinder ? MetadataSourceProcessor property firstName with lazy=false
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.AbstractPropertyHolder ? Attempting to locate auto-apply AttributeConverter for property [it.telecomitalia.strutsexample.model.Contact:firstName]
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.annotations.SimpleValueBinder ? building SimpleValue for firstName
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.annotations.PropertyBinder ? Building property firstName
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.Ejb3Column ? Binding column: Ejb3Column{table=org.hibernate.mapping.Table(Contacts), mappingColumn=lastname, insertable=true, updatable=true, unique=false}
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.annotations.PropertyBinder ? MetadataSourceProcessor property lastName with lazy=false
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.AbstractPropertyHolder ? Attempting to locate auto-apply AttributeConverter for property [it.telecomitalia.strutsexample.model.Contact:lastName]
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.annotations.SimpleValueBinder ? building SimpleValue for lastName
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.annotations.PropertyBinder ? Building property lastName
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.Ejb3Column ? Binding column: Ejb3Column{table=org.hibernate.mapping.Table(Contacts), mappingColumn=website, insertable=true, updatable=true, unique=false}
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.annotations.PropertyBinder ? MetadataSourceProcessor property website with lazy=false
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.AbstractPropertyHolder ? Attempting to locate auto-apply AttributeConverter for property [it.telecomitalia.strutsexample.model.Contact:website]
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.annotations.SimpleValueBinder ? building SimpleValue for website
    DEBUG http-bio-8080-exec-35 org.hibernate.cfg.annotations.PropertyBinder ? Building property website
    DEBUG http-bio-8080-exec-35 com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor ? Error calling method through OGNL: object: [it.telecomitalia.strutsexample.view.ContactAction@11040e2] method: [add] args: [[]]
    java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;
        at org.hibernate.cfg.annotations.EntityBinder.processComplementaryTableDefinitions(EntityBinder.java:973)
        at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:824)
        at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3845)
        at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3799)
        at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1412)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846)
        at it.telecomitalia.db.util.HibernateUtil.createSessionFactory(HibernateUtil.java:23)
        at it.telecomitalia.db.util.HibernateUtil.getSessionFactory(HibernateUtil.java:30)
        at it.telecomitalia.controller.ContactManager.add(ContactManager.java:26)
        at it.telecomitalia.strutsexample.view.ContactAction.add(ContactAction.java:43)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:870)
        at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1293)
        at ognl.ObjectMethodAccessor.callMethod(ObjectMethodAccessor.java:68)
        at
    Qualche idea?

    Grazie a chi risponderà

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.