Techie:Techie Main/Java/Hibernate/Hibernate Properties File: Difference between revisions
Created page with 'Hibernate will look for config properties in a file called hibernate.properties on the classpath. It is also possible to tell hibernate to use other files. Note, properties can…' |
No edit summary |
||
Line 18: | Line 18: | ||
== Example of a standalone java app properties file == | == Example of a standalone java app properties file == | ||
hibernate.bytecode.use_reflection_optimizer=false | |||
hibernate.connection.driver_class=org.gjt.mm.mysql.Driver | |||
hibernate.connection.username=yyyy | |||
hibernate.connection.password=xxxx | |||
hibernate.connection.url=jdbc:mysql://localhost/fantacy?autoReconnect=true | |||
hibernate.current_session_context_class=thread | |||
hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect | |||
hibernate.show_sql=false | |||
hibernate.cache.use_query_cache=false | |||
hibernate.cache.use_second_level_cache=false |
Latest revision as of 10:46, 29 May 2010
Hibernate will look for config properties in a file called hibernate.properties on the classpath. It is also possible to tell hibernate to use other files.
Note, properties can also be specified in the hibernate.cfg.xml file but by separating them out we can keep the mappings separate from the configuration of database connections. This allows us to configure the mappings within a core java project and configure the connections per application - for example we will want different connection properties for a web application and a standalone java app.
Example web app properties file
An appropriate place for this file is in the WAR file's WEB-INF/classes folder
hibernate.bytecode.use_reflection_optimizer=false hibernate.connection.datasource=java:comp/env/jdbc/FantacyDS hibernate.current_session_context_class=thread hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect hibernate.show_sql=false hibernate.cache.use_query_cache=false hibernate.cache.use_second_level_cache=false
Example of a standalone java app properties file
hibernate.bytecode.use_reflection_optimizer=false hibernate.connection.driver_class=org.gjt.mm.mysql.Driver hibernate.connection.username=yyyy hibernate.connection.password=xxxx hibernate.connection.url=jdbc:mysql://localhost/fantacy?autoReconnect=true hibernate.current_session_context_class=thread hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect hibernate.show_sql=false hibernate.cache.use_query_cache=false hibernate.cache.use_second_level_cache=false