- This topic has 8 replies, 6 voices, and was last updated 18 years, 5 months ago by
marcoshz.
-
AuthorPosts
-
Kevin HutsonMemberI 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 connectionsI 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.0here 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
September 16, 2004 at 8:40 pm #215400
Riyad KallaMemberKevin,
What does your hibernate.cfg.xml file look like?September 17, 2004 at 1:14 am #215405
peterwontnerMemberI 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()September 17, 2004 at 1:17 am #215406
peterwontnerMemberSorry that should have read (is early, not enough caffeine;))…
SessionFactory factory = config.config().buildSessionFactory()
September 20, 2004 at 12:16 am #215547
support-jeffMemberAlso, 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.
September 20, 2004 at 6:23 pm #215648
Kevin HutsonMemberHi 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
February 22, 2007 at 12:10 pm #266520
marcoshzMemberHi 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.
February 27, 2007 at 5:37 am #266677
Brian FernandesModeratorA 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.
February 27, 2007 at 9:26 am #266687
marcoshzMemberNow I see it, it’s a nice helper class. Thanx a lot 🙂
-
AuthorPosts