facebook

Hibernate/MyEclipse error – no dialect set

  1. MyEclipse IDE
  2.  > 
  3. General Development
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #215397 Reply

    Kevin Hutson
    Member

    I am trying to use an existing database connection to a MySQL database to Create a Hibernate mapping with MyEclipse.

    The wizard seems to work and the classes that it generates compile.
    However, when I try to use Hibernate to add a row to my table, I get a very puzzling error. It appears that my project is not setup correctly.
    Now, I am a little new to Hibernate, but not to MyEclipse.
    So, maybe it’s me.
    Here is the error I get.

    16:19:25,927 WARN SettingsFactory:50 – No dialect set – using GenericDialect: The dialect was not set. Set the property hibernate.dialect.
    16:19:25,937 WARN UserSuppliedConnectionProvider:25 – No connection properties specified – the user must supply JDBC connections

    I do have a hibernate.cgf.xml, mytable.hbm.xml and log4j.properties file.
    It has generated the Java classes for me to use.

    Why would I get these errors?

    Let me know what additional information would be helpful to troubleshoot this issue.

    Here is what I am using:
    mysql Ver 12.22 Distrib 4.0.17, for Win95/Win98 (i32)
    MyEclipse 3.8.1
    Eclipse Version 3.0.0

    here is a main code snippet, for what it is worth..

        public static void main(String[] args) {
            
            
            
            logger.info("start!");
            
            Configuration config  = new Configuration();
            
            Transaction tx = null;
            Session session = null;
            try {
                logger.info("trying....!");
    
                SessionFactory sessionFactory = config.buildSessionFactory();
                
                 session = sessionFactory.openSession();
                
                tx = session.beginTransaction();
                
                Dpalline dpl = new Dpalline(new DpallineKey(), "here is my description");
    
                session.save(dpl);
                logger.info("saved?!");
                
            } catch (Exception e) {
                // TODO: handle exception
            } finally {
                
                    try {
                        session.close();
        
                    } catch (Exception e) {
                        // TODO: handle exception
                    }
            }
            
            logger.info("done!");
            
        }

    Cheers,

    Kevin Hutson

    #215400

    Riyad Kalla
    Member

    Kevin,
    What does your hibernate.cfg.xml file look like?

    #215405

    peterwontner
    Member

    I believe the error youare having is because you are not calling configure() on the Configurations object before building the session factory…

    Configuration config = new Configuration()
    Session session = config.configure().buildSessionFactory()

    #215406

    peterwontner
    Member

    Sorry that should have read (is early, not enough caffeine;))…

    SessionFactory factory = config.config().buildSessionFactory()

    #215547

    support-jeff
    Member

    Also, when you added Hibernate capabilities to your project, did it create a SessionFactory class for you (not the net.sourceforge.hibernate.SessionFactory, rather a custom one). This class is specifically generated to perform the configuration step for you and allow easy access to sessions. At the least, you can look at that code for examples.

    #215648

    Kevin Hutson
    Member

    Hi everyone,

    All of those replies were very helpful.
    Thanks so much!
    Sorry for the delay in getting back to you.

    The help on the configure part was useful.
    I had one other major problem. I wasn’t using commit. Doh!

    Here is the resulting code for the next person who needs a VERY simple. So, after running the wizard, a simple class like this can be used to test an Insert. Of course, you will need to create your own custom constructor.

    
    package foo;
    
    import org.apache.log4j.Logger;
    
    import net.sf.hibernate.Session;
    import net.sf.hibernate.Transaction;
    import net.sf.hibernate.cfg.Configuration;
    
    public class KevinAccount1 {
        private static final Logger logger = Logger.getLogger(KevinAccount1.class);
    
        public static void main(String[] args) {
            
            logger.info("start!");
            
            Configuration config  = new Configuration();
            
            Transaction tx = null;
            Session session = null;
            try {
                logger.info("trying....!");
    
                session=HibernateSessionFactory.currentSession();
                tx = session.beginTransaction();
                
                logger.info("ok...?");
                // add a new account record
                Account account = new Account("myaccount5", "me@me.com","mr","greenjeans",
                    "a1","123 main","mailbox1","austin","tx","456789","us","123-233");
                
                session.save(account);
                // don't forget to commit. duh!
                tx.commit();
                logger.info("saved?!");
                
            } catch (Exception e) {
                logger.error("yikes, an error!" + e.getMessage());
                e.printStackTrace();
            } finally {
                
                    try {
                        logger.info("closing session...");
                        session.close();
                    } catch (Exception e) {
                        logger.error("unable to close session");
                    }
            }
            
            logger.info("done!");
            
        }
    }
    

    Cheers,

    Kevin

    #266520

    marcoshz
    Member

    Hi I had the same problem. I was following an example of “Hibernate: A developers Notebook” from O’Reilly, It’s a good book but it have some errors (and it’s very outdated for Hib3.2).

    The code now works, Thanx a lot for this help, It seems quite obvious now that you say it 🙂

    But I still have a question, support-jeff said that

    Also, when you added Hibernate capabilities to your project, did it create a SessionFactory class for you (not the net.sourceforge.hibernate.SessionFactory, rather a custom one). This class is specifically generated to perform the configuration step for you and allow easy access to sessions.

    That was a fact or a question?? because I can’t find such SessionFactory generated class.

    #266677

    Brian Fernandes
    Moderator

    A SessionFactory class will be generated if you choose the option during capability addition. Try adding Hibernate capabilities to a test Java project and observe the last step in the wizard.
    This class would be automatically generated for you (if you don’t already have it) if you RE from a database and choose to use Basic DAOs. The default name for this class is HibernateSessionFactory.

    Hope this helps.

    #266687

    marcoshz
    Member

    Now I see it, it’s a nice helper class. Thanx a lot 🙂

Viewing 9 posts - 1 through 9 (of 9 total)
Reply To: Hibernate/MyEclipse error – no dialect set

You must be logged in to post in the forum log in