1. Transactions
Two types of transactions:
① JDBC transaction: the transaction of a single database
A sesisonfactory corresponds to a database, implemented using JDBC
Templates for common code:
Session session = null; Transaction tx =null; try { session = sessionFactory.openSession(); tx = session.beginTransaction(); //process tx.commit(); } catch(HibernateException e){ if(tx != null)tx.rollback();throw e; }finally { if (session != null)s
Advantages and disadvantages of struts2,spring,hibernate frameworkThe advantages of the STRUTS2 Framework (MVC framework) are as follows:1) realize the MVC pattern, the hierarchy structure is clear, so that the programmer only needs to focus on the realization of business logic;2) Rich tag library, greatly improve the efficiency of development;3) Struts2 provides
Spring + hibernate + tapestry is a new popular Java development framework. This article provides an example of processing the orcale blob field content under this development framework:
Orcale blob database ing in Hibernate is private byte [] ZP; // photo "ZP" blob, which
: Persisting objects to columnstore, such as Apache HBase, Apache Cassandra, hypertable, persistent to key-value storage such as Voldermort, Redis, etc., persisted to SQL database, such as MySQL, HSQLDB; You can also make Hadoop HDFs storage for files; Data access: Use the Java API to easily access data without regard to the location of the data; Indexing: Persisting objects to Apache Lucene and SOLR indexes, using the Gora API to access or query data
table based on the specified primary key value, and then when it needs to use the relevant information of the Usersex table, Hibernate takes UserInfo's primary key value again to check the Connect connection table, and injects the found Usersex instance set into the UserInfo collection properties.In summary, we introduce some common relationships in relational database, and introduce how Hibernate uses ann
Hibernate Object Persistence frameworkJDBC :( Java Data Base Connectivity) java Database Connection
The java. SQL package provides JDBC APIs to write program code for accessing the database. common interfaces and classes include the following:
DriverManager: Driver manager, responsible for creating database Connection:
First, doubtsAll along, when I used the SSH framework, I often found that the latter had doubts about how to use hibernate or how to configure hibernate to operate the database,A period of time to learn below I summarize the common DAO layer configuration.Second, commonly used hibernate operation DAO
The first
.getemps (). Add (Emp4); //Save Project I and project twoSession.save (Pro1); Session.save (PRO2); //Commit a transactionTx.commit (); //Close Connectionhibernateutil.closesession (); }}The above code, we can find that we just saved the project, and did not manually add to save the employee's code, nor manually add the table to save the relationship between employees and the project codeWe can see the SQL that hibernate helped us generateHibern
PairIn hibernate, set attributes are very common and important in hibernate ing files. It is more important to understand and master common set attributes. In the hibernate configuration file, for example, each person's test score is a typical map structure, and each course corresponds to a score. Or a simpler set of attributes, the department of an enterprise, a
Persistent object uniquely identifies--oid1) The primary key in the database can be used to distinguish whether two objects are the same2) Whether the memory address of the object used in the Java language distinguishes between objects3) Use OID in Hibernate to distinguish objects from the sameHibernate considers that each of the different objects should have a unique identifier, which is called the OID;In
= Configuration.buildsessionfactory ();Get the Session object (the session object here is equivalent to connection in JDBC)Session session = Factory.opensession ();Open transactionTransaction ts = session.begintransaction ();try{CRUD operations are performed hereAdd Operation userUser user = new user ();User.set (...);Session.save (user);Find operationsUser user = Session.get (user.class, "UID");//Find the object under the specified ID Other query methodsUsing the HQL statement with the query
Compared with Microsoft's LINQ-to-SQL or EF framework, "Hibernate is not easy for eclipse Integrated Development". The following are the steps for beginners:
I. preparations:
1,First download eclipse (Official Website http://eclipse.org/) Note: such as the Local has installed eclipse, can skip
2,Download the latest version of hibernate (has reached version
Tags: style blog http io os ar java for dataSome of the previous write a lot, we first read the previous article, portalThe specific resources will be uploaded to the resource.Attached address: Mysql.zip startIntegrating Springmvc+spring+hibernate framework with MAVENBefore we directly build the preparation and resource configuration are written, the following in
Hibernate requires the following States in his life cycle for Java objects to be persisted:1, temporary State (transient): Just created with the new statement, has not been persisted, not in the session cache. A Java object that is in a temporary state is called a temporary object.2, persistent State (persistent): Has been persisted, added to the session, in the
A lot of detours when learning the framework of the hibernate frame.Version:Record the first hibernateThe first is the structure of the building:Hibernate.cfg.xml File Contents:Configuration Public"-//hibernate/hibernate Configuration DTD 3.0//en" "Http://www.hibernate.org/dtd/hibe
It's been a long time since I used the spring framework, and it's been struts2+hibernate4 to build Web projects, and lately, to learn something about spring, spring is the most widely used framework now, and will work in this industry, so it's necessary to learn.The spring framework is added first and can be run correctly;The
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.