---How do you call a state of an entity object that is never persisted and not associated with any Session?
A: transient
---Transient instances may be made persistent by calling which of the Session method (Choose all that apply)?
A: Save, Update, Persist, Write, SaveOrUpdate.
Transient instances may be made persistent by calling save, persist or saveOrUpdate. There is no such method like write and update - updates the persistent instance with the identifier of the given detached instance not transient.
---Is there a difference between
Pet pet = (Pet) session.get(Pet.class, petId);
and
Pet pet = (Pet) session.load(Pet.class, petId);
?
A: There is a difference - if session.load can't find the object in the cache or database it throws an exception, while session.get just returns null.
---Which of the following LockMode always increments version for versioned entities.
|
|
READ
|
|
|
WRITE
|
|
+
|
FORCE
|
|
|
UPGRADE
|
|
|
INCREMENT
|
---
What kind of hibernate inheritance mapping strategies represents the hibernate mapping file (Person.hbm.xml)?
<hibernate-mapping>
<class
name="Person"
table="PERSON"
>
<id
name="id"
column="id"
type="long"
>
<generator class="increment"/>
</id>
<property name="name" column="name"/>
<joined-subclass
name="Worker"
table="WORKER"
>
<key column="id"/>
<property name="salary" column="salary"/>
</joined-subclass>
<joined-subclass
name="Student"
table="STUDENT"
>
<key column="id"/>
<property name="grade" column="salary"/>
</joined-subclass>
</class>
</hibernate-mapping>
+
|
Table per subclass
|
|
Table per class hierarchy
|
|
Table per concrete class
|
|
implicit polymorphism
|
---Assume that you want to see what SQL queries are used by Hibernate during the execution of the HQL commands. Fill the gap in order to enable the underlaying SQL commands logging.
<property name="__show_sql ___">true</property>
--- Given:
@Entity
public class Foo {
@Id
private int id;
....
}
Choose correct statement.
+
|
It's a valid example of the @Id annotation usage.
|
|
It's not valid as @Id should be associated with a getter method (getId()) not a field.
|
|
It's not valid as @Id should be associated with both a field and a getter (getId()) method.
|
|
It's not valid as @Id should be associated with both a field and a setter (setId()) method.
|
---Hibernate provides <native>
inheritance strategy indicating that we want to use native SQL inheritance mechanism. (F)
SQL does not provide inheritance - that is one of the Object/Relation mismatches.
---Object Relational Mapping of hibernate is used to select, insert, update and delete the records form the underlying table. (T)
---Consider the following snippet:
<set name="foos" ______="joinPoint">
<key column="keyCol" />
<many-to-many class="Foo" />
</set>
Fill the gap in order to make the snippet above valid.
A: table
Many-to-many relationships requires setting the name of the table used to perform the join.
---Hibernate doesn't provide its own connection pooling facility i.e. you have to use some third parties pooling implementation like DBCP.(F)
EX: Hibernate provides its own internal connection pooling facility. However the latter is intended to be used during a development phase - third party solutions are recommended to be used in the production.
---Collection can be used as a key type for a Hibernate map.(F)
Ex: Keys of Hibernate maps can be of any type (including composite type) except the collection types.
---Hibernate provides its own connection pooling facility. The latter is recommended to be used in the production instead of the third parties pooling implementation like DBCP.
The last sentence is true. (F)
Hibernate provides its own internal connection pooling facility. However the latter is intended to be used during a development phase - third party solutions are recommended to be used in the production.
---How many table(s) in a database represents the hibernate mapping file (Person.hbm.xml)?
<hibernate-mapping>
<class name="Person">
<id name="id">
<generator class="increment"/>
</id>
<discriminator column="PERSON_TYPE" type="string"/>
<property name="name"/>
<subclass name="Worker">
<property name="salary" column="SALARY"/>
</subclass>
<subclass name="Student">
<property name="grade" column="GRADE"/>
</subclass>
</class>
</hibernate-mapping>
One table (PERSON) (T)
|
Three tables (PERSON, WORKER, STUDENT)
|
The quantity of tables depends of the type of database to which hibernate is connected
|
Ex:The mapping file represents the table per class hierarchy inheritance strategy and there is only one table for class hierarchy.
---Is it possible using annotations to declare readable name of a foreign key constraint in joined inheritance type ? (T)
---Consider the following code:
Session session;
PersistedEntity entity = session.get(PersistedEntity.class, new Integer(1));
entity.setValue("New Value");
session.saveOrUpdate(entity);
session.close();
If there is record in database for class PersistedEntity with ID of 1, the changes to the property 'value' will be correctly saved in the database. (F)
Ex: The Hibernate framework has already associated the id 1 with the entity. When you try to saveOrUpdate it, it will complain that the object already exist in the session by throwing an HibernateException.
---Which of the following scopes of identity are defined in Hibernate? (all true)
No identity scope(def) : a database row can be represented as two java objects ..this is not supported as two objects can modify a record...
|
Transacion scoped identity:In the context of a transaction a single object instance that represents a database row. Allows some caching to be done at transaction level.
|
process scoped identity :one instance per row in whole jvm.
|
---Select all valid Hibernate queries.
|
|
select emp from Employee emp |
|
|
select emp.id from Employee emp where exists ( from Education where name like 'Foo' and emp.id = employee.id ) |
|
|
select emp.id from Employee emp where exists ( from Education edu where edu.name like 'Foo' and emp.id = employee.id ) |
|
|
select * from Employee as emp where exists ( from Education as edu where edu.name like 'Foo' and emp.id = employee.id ) |
|
|
from Employee as emp where exists ( from Education where name like 'Foo' and emp.id = employee.id ) |
explanation |
The use of select * is not allowed in HQL. As an alternative you can leave out select * or use (in this case) select emp . |
---In Hibernate which of the following properties of persistent class mapping have to be added (separately) to enable optimistic locking? (Choose all that apply)
+
|
<timestamp>
|
|
<lock>
|
|
<optimistic-locking>
|
+
|
<version>
|
Ex::Optimistic locking is enabled when you add a <version> or a <timestamp> property to a persistent class mapping.
---Select the right lock levels that may be acquired by Hibernate.
+
|
LockMode.WRITE
|
+
|
LockMode.READ
|
|
LockMode.READ_WRITE
|
+
|
LockMode.UPGRADE
|
+
|
LockMode.UPGRADE_NOWAIT
|
+
|
LockMode.NONE
|
There is no LockMode.READ_WRITE.
---By default, Hibernate works in the autocommit mode i.e. starts and commits the transaction after each operation like load or save. (F)
Ex:You have to flush the session or commit the transaction explicitly.
---One of the Hibernate supported inheritance mapping strategies is
table per class hierarchy (An entire class hierarchy can be mapped to a single table).
Disadvantage of the strategy is that columns for properties declared by subclasses must be declared to be nullable. (T)
---What's the state of a newly created object?
+
|
Transient.
|
|
Persistent.
|
|
Detached.
|
Ex: Objects created with a new operator are transient (are not associated with a database).
---Which is default cache service in Hibernate 3?
+
|
EHCache
|
|
OSCache
|
|
TreeCache
|
|
SwarmCache
|
Default cache service in Hibernate 3 is EHCache
---Assume, that U have two persistent classes with the same
unqualified name, for example
com.jbb.JBB
and
org.jbb.JBB
.Hibernate will throw an exception if you attempt to assign two classes to the same unqualified name when
auto-import
attribute set to "false".
(F)
If you have two persistent classes with the same (unqualified) name, you should set auto-import="false". Hibernate will throw an exception if you attempt to assign two classes to the same "imported" name
posted on 2007-06-15 15:11
Sun River 阅读(509)
评论(0) 编辑 收藏 所属分类:
Hibernate