Hi all,
I have tried to find the solution to this problem which I am sure is out there somewhere.
I am using hibernate 2.1. I am trying to use it inside of JBoss although not using the hibernate that comes with JBoss. The jar that contains my .class, .jar and .hbm.xml files also contains my hibernate.properties file. If I understand correctly this file only needs to be in the classpath and not in a specific location. I am putting the jars in the server/default/deploy directory on the jboss server.
Well, when I try to create an object it gives me this error
......
2004-06-02 20:55:04,089 INFO [com.camp.server.menu.dm.dm_menu] Creating dm_general
2004-06-02 20:55:04,151 INFO [net.sf.hibernate.cfg.Environment] Hibernate 2.1.3
2004-06-02 20:55:04,170 INFO [net.sf.hibernate.cfg.Environment] hibernate.properties not found
2004-06-02 20:55:04,177 INFO [net.sf.hibernate.cfg.Environment] using CGLIB reflection optimizer
2004-06-02 20:55:04,199 INFO [net.sf.hibernate.cfg.Configuration] Mapping resource: com/camp/common/menu/Menu.hbm.xml
2004-06-02 20:55:04,226 DEBUG [net.sf.hibernate.util.DTDEntityResolver] trying to locate
http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
2004-06-02 20:55:04,228 DEBUG [net.sf.hibernate.util.DTDEntityResolver] found
http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
2004-06-02 20:55:04,494 INFO [net.sf.hibernate.cfg.Binder] Mapping class: com.camp.common.menu.Menu -> tblMenu
2004-06-02 20:55:04,927 DEBUG [net.sf.hibernate.cfg.Binder] Mapped property: menu_id -> id_menu, type: integer
2004-06-02 20:55:04,994 DEBUG [net.sf.hibernate.cfg.Binder] Mapped property: menu_name -> name, type: string
2004-06-02 20:55:04,995 ERROR [net.sf.hibernate.cfg.Configuration] Could not compile the mapping document
net.sf.hibernate.MappingException: Problem trying to set property type by reflection
at net.sf.hibernate.mapping.SimpleValue.setTypeByReflection(SimpleValue.java:183)
at net.sf.hibernate.cfg.Binder.createProperty(Binder.java:1057)
.......
.....
A few things.
1. It cannot find hibernate.properties. I have put this file into multiple locations but it just will not be found.
2. Why is it trying to locate
http://hibernate.sourceforge.net
3. I notice that some people use properties.hbm.xml instead of the plain text hibernate.properties. Is there a reason for that and should I be using the xml version?
4. Should the jar with the hibernate.properties file in it be in the server/default/lib directory on the JBoss server instead of the server/default/deploy
5. The above errors are run with the code below. As can be seen, because of my frustration I added the properties in manually to try and get stuff to work. That is why it all seems to work and only gives a problem with the reflection. Any ideas as to what is causing the reflection problem would be appreciated.
public dm_menu(String _menu_name) throws Exception {
log.info("Creating dm_general");
// query to issue
String query =
"select * from menu "
+ "in class com.camp.common.menu.Menu "
+ "where lower(menu.name)=lower(:name)";
// search for what?
String name = _menu_name;
// init
Configuration cfg = new Configuration()
.addClass(Menu.class);
cfg.setProperty("hibernate.connection.username","postgres");
cfg.setProperty("hibernate.connection.password","");
cfg.setProperty("hibernate.connection.url","jdbc:postgresql://localhost/camp");
cfg.setProperty("hibernate.connection.driver_class","org.postgresql.Driver");
cfg.setProperty("hibernate.dialect","net.sf.hibernate.dialect.HSQLDialect");
SessionFactory sf = cfg.buildSessionFactory();
// open session
Session sess = sf.openSession();
// search and return
List list = sess.find(query, name,
Hibernate.STRING);
if (list.size() == 0) {
System.out.println("No products named "
+ name);
System.exit(0);
}
Menu m = (Menu) list.get(0);
sess.close();
System.out.println("Found product: " + m);
}
Any help on any of this would be awesome. Thanks so much. If ther are other sources that I should have looked at the links to those instead would
also be great.
Cheers
Tom