What is the use of cascade in hbm file?
Answered by: anupsadhwani60
View all answers by anupsadhwani60
Member Since Sep-2007 | Answered On : Sep 16th, 2007
1) cascade="none", the default, tells Hibernate to ignore the association.
2) cascade="save-update" tells Hibernate to navigate the association when the
transaction is committed and when an object is passed to save() or
update() and save newly instantiated transient instances and persist changes to
detached instances.
3) cascade="delete" tells Hibernate to navigate the association and delete persistent
instances when an object is passed to delete().
4) cascade="all" means to cascade both save-update and delete, as well as
calls to evict and lock.
5) cascade="all-delete-orphan" means the same as cascade="all" but, in addition,
Hibernate deletes any persistent entity instance that has been removed
(dereferenced) from the association (for example, from a collection).
6) cascade="delete-orphan" Hibernate will delete any persistent entity
instance that has been removed (dereferenced) from the association (for
example, from a collection).
Using cascade property we can ensure relationship with parent to child
Whenever we have a parent child relation ship, if parent record is changed then child record should also be changed.
Primary key must be reflected in the child key
What is the latest version of hibernate using in current industry?
4.1.4
3.6 is the current version but while executing an application you wont get log messages like in Hibernate 3.2
What is the main advantage of using the hibernate than using the SQL
Hibernate provide object oriented functionality and hibernate easily migrate different database without any query changes.
- Hibernate is something which is totally based on ObjectOrientedProgramming concept.where as SQL is based on Querys .But Hibernate also uses sql queries but it is using Objects to handle the res...
How to create primary key using hibernate?
In hibernate mapping file
Code
.hbm.xml add <id> under <class> <class name="class name" table="table name"> <id name="pojo variable name" column="table column name"/>//primarykey mapping <property name="pojo variable name" column="table column name/>//non-primarykey mapping </class> Answered by: mani.sivapuram on: Feb 21st, 2011First you have to do is when you are creating table itself you have to give the primary key for any one of the column and then in the hibernate take hbm file in that there is a tag like <id&g...
When would you use hibernate and spring JDBC template ?
Spring jdbc and hibernate are working in same way ..it depends what technologies we are using
Advantages of Hibernate Over EJB Entity bean is also used for object oriented view. It needs lot of things to configure for make it possible and Lot of coding need for it. After all these performance ...
Basically Ejb and Hibenate is enterly different one But having realtion with Entitybean in Ejb and Hibernate. Entity bean is also used for object orientd view . It need lot things to configures fo mak...
How do you store a image in Oracle using hibernate ?
How do we create new table apart from mapping with existing table ?
Hibernate automatically creates new tables if there are corresponding POJOs. If you know how to write/read to/from an existing table using Hibernate, then you can easily create a table. Step#1: Creat...
What is database persistence?How well it is implemented in hibernate
There are mainly three states in hibernate a) Transient state b) Persistant state c) Detatched state Take the employee object place the data in that object like usename, password, empid. Now th...
Preserving the data inside a database is database persistence. Persistence is once of the fundamental concepts of application developement. There are many alternatives to implement persistence. Object...
What is the advantage of hibernate over JDBC?
Hibernate Advantages:Productivity: Improves the productivity by eliminating the JDBC tedious code. ...
Advantages OF Hibernate: - First of all will provide business entity form of representation of DB tables. - Hibernate provides an interface to develop our application code which is not specific to an...
How jpa and hibernate are related as per ejb 3 specifications?
first things first ..i have just seen ppl venting thier personal grudge over java / jpa or whatever over this forum.suns official sacceptence that jpa is a failure. please lets keep it out.as for the ...
JPA is official acceptance from SUN about its failure on EJB. It has to abandon its EJB model to go to ORM model. Finally, Sun should provide developers some tools to migrate Java programs to .net easily with out pain
Why do you need orm tools like hibernate?
since we want to reduce burden on the developer so for big projects if any maintaince is requered then problem finding and bug fixing is easy in case of hibernate.I can obey with one thing it we need ...
Hibernate allows the application developer to concentrate on the business logic instead of writing complex SQLs. Aprt from this hibernate would take care of the database connections and managing conne...
What is component mapping in hibernate?
I will explain one realtime scenario here.Consider one Address class as given belowpublic class Address{private Integer doorNo;private String street;//provide setters and getters for above properties}...
A component is a contained object that is persisted as a value type ,not an entity reference.eg)public class person{private Name name;public Name getName(){ return name;}public void setName(Name name)...
What is the difference between hibernate and spring
Hibernate is used to interact with database.i.e if we want to save some data then we use hibernate or jdbc or some other tools available in the market.But it is not possible for struts or spring to st...
Hibernate is ORM tool used for data persistency.Spring is a framework for enterprise applications with default APIs for presentation, middle tiers and presistence layers and allows to integrate with ...
JdbcTemplate is configured in spring configuration file like first datasource object is created and then datasource object is given to jdbcTemplate using setter method and jdbcTemplate object is given...
Spring provides support for both hibernate and JDBC.It provides template classes which contains all common code.But JDBC as we all know is not an ORM tool it does not represent rows as objects whereas Hibernate does that.
when we call the load() method as given below  ...
Proxies are created dynamically by subclassing your object at runtime. The subclass has all the methods of the parent, and when any of the methods are accessed, the proxy loads up the real object from...
Since in case of jdbc autocommit is always true but in case of hibernate after executing all the sql statements only it process the commit operation this is called as transaction management.But this t...
In hibernate objects are loosely coupled providing flexibility during integration with other databases or applications
In J2EE inheritance can not be achieved directly for the objects mapping
One-to-one mapping is mandatory in J2EE
since according to the hibernate specifications hbm file is configured in such a way that one primary key shoud be configured in id tag of hbm file.and other properties are configured in property tags...
What is lazy fetching in hibernate
Lazy fetching means for example in hibernate if we use load() method then load() is lazy fetching i.e it is not going to touch the database until we write empobject.getString("eno");So when we write a...
Lazy loading is the responsibility is that to load the objects for its parent
In mapping file, if
you want to load the child objects while loading the parent it will wont load coz by default load = true
so
you have to specify lazy = false
here child class become parent while loading the objects.
Editorial / Best Answer
Answered by: promisingram
View all answers by promisingram
Member Since Oct-2008 | Answered On : Oct 19th, 2008
Use update() if you are sure that the session does not contain an already persistent instance with the same identifier, and merge() if you want to merge your modifications at any time without consideration of the state of the session. In other words, update() is usually the first method you would call in a fresh session, ensuring that reattachment of your detached instances is the first operation that is executed.
suppose you have detached object (means after closing session persistence object becomes detached object) and you have done some changes in this object with help of setter method now you created new ...
In Hibernate session can maintain only one object in persistent state with same id number. while converting a detached object into persistent,if already that session has a persistent object with the s...