In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to realize Hibernate mapping". The explanation in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian and go deep into it slowly to study and learn "how to realize Hibernate mapping" together.
I was impressed with Hibernate, but one problem I encountered was trying to insert an indirect layer when using Hibernate for data mapping for unit testing. This additional layer is very fragile and difficult to write. The actual deployment version simply passes through Hibernate specific implementations. Worse, the mock version is more complex than the real "production" version simply because it has no basic object memory and Hibernate mapping.
I also use a lot of complex Hibernate queries and want to unit test important parts of my application. However, it is not a good idea to test a live database because this almost always creates maintenance problems. Also, since tests are independent of each other, using the same primary key in the test context data means that code must be created to clean up the database before each test, which becomes a real problem when a large number of relationships are involved.
By using HSQLDB and Hibernate's powerful pattern generation tools, you can unit test the application mapping layer and find countless bugs in object queries that were previously impossible to do manually. With the following technical overview, you can test your entire application during development without damage in the test active area.
Set HSQLDB
HSQLDB 1.7.3.0 version was previously used. To use the in-memory version of the database, you need to activate the static loader for org.hsqldb.jdbcDriver. When you get a JDBC connection, you can use a JDBC url such as jdbc:hspldb:mem:yourdb, where 'yourdb' is the name of the in-memory database you want to use.
Because I use Hibernate (3.0 beta 4), I have little contact with the actual live JDBC object. Instead, I can let Hibernate do a lot of heavy lifting, including automatically creating database schemas from Hibernate mapping files. Because Hibernate creates its own proprietary connection pool, it automatically loads the HSQLDB JDBC driver based on configuration code in the TestSchema class. Here is the static initializer for this class.
public class TestSchema {
static {
Configuration config = new Configuration().
setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect").
setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver").
setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:baseball").
setProperty("hibernate.connection.username", "sa").
setProperty("hibernate.connection.password", "").
setProperty("hibernate.connection.pool_size", "1").
setProperty("hibernate.connection.autocommit", "true").
setProperty("hibernate.cache.provider_class", "
org.hibernate.cache.HashtableCacheProvider").
setProperty("hibernate.hbm2ddl.auto", "create-drop").
setProperty("hibernate.show_sql", "true").
addClass(Player.class).
addClass(BattingStint.class).
addClass(FieldingStint.class).
addClass(PitchingStint.class);
HibernateUtil.setSessionFactory(config.buildSessionFactory());
}
Thank you for reading, the above is "Hibernate mapping how to achieve" content, after the study of this article, I believe we have a deeper understanding of how to achieve Hibernate mapping, the specific use of the situation also needs to be verified. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.