Article View: pl.comp.lang.java
Article #153404Hibernate, annotations i brak hibernate.cfg.xml
From: Sebastian Biały
Date: Mon, 23 Apr 2012 20:57
Date: Mon, 23 Apr 2012 20:57
37 lines
2155 bytes
2155 bytes
Chcę użyć *wyłacznie* annotations z hibernate, *żadnych* metadanych przez xml. Niestety już na starcie dostałem w łeb: org.hibernate.cfg.Configuration configuration = new org.hibernate.cfg.Configuration(); java.util.Properties properties = new java.util.Properties(); properties.put( org.hibernate.cfg.Environment.DIALECT, "org.hibernate.dialect.MySQLDialect" ); properties.put( "hibernate.connection.driver_class", "org.mysql.jdbc.Driver" ); properties.put( "hibernate.connection.url", "jdbc:mysql://localhost/spam" ); properties.put( "hibernate.connection.username", "foo" ); properties.put( "hibernate.connection.password", "bar" ); properties.put( "hibernate.show_sql", "true" ); configuration .addAnnotatedClass( org.bad.page.Foo.class ) .setProperties( properties ) .configure() ; Po tym kawalku kodu dostaje: Configuring from resource: /hibernate.cfg.xml Exception in thread "main" org.hibernate.HibernateException: /hibernate.cfg.xml not found Jak to wyłaczyć aby konfiguracja pochodziła wyłacznie z kodu i annotations? Google czesam od godziny i pełno przykladów z annotations, w których ... oczywiście jest hibernate.cfg.xml. Jestem ślepy lub nie potrafie zadać pytania googlowi. Teoretycznie nie podaje do configure ściezki ,ale configure() bierze ją domyślna :/
Technical Details
Message-ID:
<jn4foj$kaj$1@inews.gazeta.pl>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!not-for-mailShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!not-for-mail From: Sebastian Biały <heby@poczta.onet.pl> Newsgroups: pl.comp.lang.java Subject: Hibernate, annotations i brak hibernate.cfg.xml Date: Mon, 23 Apr 2012 22:57:50 +0200 Organization: "Portal Gazeta.pl -> http://www.gazeta.pl" Lines: 37 Message-ID: <jn4foj$kaj$1@inews.gazeta.pl> NNTP-Posting-Host: 83.142.222.167 Mime-Version: 1.0 X-Trace: inews.gazeta.pl 1335214675 20819 83.142.222.167 (23 Apr 2012 20:57:55 GMT) X-Complaints-To: usenet@agora.pl NNTP-Posting-Date: Mon, 23 Apr 2012 20:57:55 +0000 (UTC) X-User: sebo.bialy User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.16) Gecko/20101125 Thunderbird/3.0.11 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit