Internal Test pen Questions for the use of Hibernate to develop rental systems

Source: Internet
Author: User
Tags bulk insert

Internal test pen questions for the use of Hibernate to develop rental systems

First, the choice of questions (a total of 25 questions, 2.5 points per question, select one or more, the selection of the wrong choice is not divided)

1. In Hibernate, the following statement about the primary key generator is wrong (C).

A Increment can be used for primary keys of type long, short, or byte

B Identity for databases that support identity columns such as SQL Server, DB2, MySQL, and so on

C Sequence for databases such as Oracle, SQL Server, and other supporting sequences

D Native by hibernate based on the underlying database to determine what the primary key generation strategy, is the use of the database to generate the value of the primary key

2. In Hibernate, the right thing to say about dirty checking and refreshing the cache is (AB).

A Dirty checks occur when a transaction commits

B The flush () method of the session is the method of refreshing the cache

C The flush () method of the session is not invoked until the commit () method of the session is executed

D Call the Flush () method before calling the commit () method when writing code

3. Use HQL to query all department information, the following is correct (AD).

A From Dept

B SELECT * FROM Cn.jbit.demo.entity.Dept

C Select Dept from Cn.jbit.demo.entity.Dept D

D Select D from Dept D

4. For the list () and iterate () methods of the query interface, it is correct to say (AD).

A Executes the list () method to query all eligible records

B Execute the Iterate () method to query all eligible records

C Executes the list () method to query all eligible primary key values

D Executes the iterate () method to query all eligible primary key values

5. In Hql, the method for binding parameters of the query interface is correct (ABCD).

A The Setparameter () method is used to bind arguments of any type

B Setparameter () There is an overloaded method

C SetProperties () There is an overloaded method

D The SetProperties () method is used to bind named arguments

6. In Hibernate, for the following mapping configuration, it is wrong to say (D).

<class name= "cn.jbit.hibernatedemo.entity.Emp" table= "EMP" schema= "Scott" >

<id name= "EmpNo" column= "EmpNo" type= "Java.lang.Integer" >

<generator class= "Assigned"/>

</id>

<property name= "Salary" type= "java.lang.Double" column= "SAL"/>

<property name= "HireDate" type= "Java.util.Date"/>

<many-to-one

Name= "Dept"

Column= "DEPTNO"

Class= "Cn.jbit.hibernatedemo.entity.Dept"

/>

</class>

A This configuration information describes the mapping of the CN.JBIT.HIBERNATEDEMO.ENTITY.EMP class and the EMP table

B That describes the EMP table for Scott users.

C The name attribute value in the <many-to-one> tag dept is the property name of the Cn.jbit.hibernatedemo.entity.Emp class

D The column attribute value in the <many-to-one> tag Deptno is the primary key name of the Dept table

7. In the hibernate mapping file, the inverse attribute is said to be correct (ACD).

A The inverse property has two values: true, False

B <many-to-one> tags have inverse properties

C <set> tags have inverse properties

D The inverse property is used to specify the party that maintains the association relationship

8. In the hibernate mapping file, it is wrong to say that the deferred load configuration is (BD)

A <class> tag in the lazy attribute optional value: True, False

B Optional values for the lazy attribute in the <set> tab: True, proxy, and No-proxy

C < set> tag in the lazy attribute optional value: True, Extra, and false

D The optional value of the lazy attribute in the <many-to-one> tag: proxy, True, and False

9. In the hibernate mapping file, the <component> tag statement is correct (ABC).

A <component> tags for mapping component classes

B <component> tags by <parent> specifies the whole class to which the component class belongs

C <component> tags by <property> specifying properties of the component class

D <component> tag has ID, name, class attribute

10. MyBatis the root element of the specified configuration file is using (B).

A <sqlMapConfig>

B <configuration>

C <setting>

D <environments>

11. In MyBatis, the value of Executortype includes (ABD).

A Executortype.simple

B Executortype.batch

C Executortype.execute

D Executortype.reuse

Explain:

An unexpected Executortype
Public final enum Org.apache.ibatis.session.ExecutorType {

Field descriptor #8 Lorg/apache/ibatis/session/executortype;
public static final enum Org.apache.ibatis.session.ExecutorType simple;

Field descriptor #8 Lorg/apache/ibatis/session/executortype;
public static final enum Org.apache.ibatis.session.ExecutorType reuse;

Field descriptor #8 Lorg/apache/ibatis/session/executortype;
public static final enum Org.apache.ibatis.session.ExecutorType BATCH;

12. The error about hibernate caching is (CD).

A Hibernate caches generally fall into three categories: first-level cache, level two cache, and query cache

B The evict () method of the session is used to purge the specified persisted object from the cache

C The clear () method of the session is used to flush the cache

D The flush () method of the session is used to purge all persisted objects from the cache

13. Regarding the connection query of HQL, it is wrong to say (D).

A Inner JOIN or join for inner joins

B INNER JOIN fetch or join FETCH for urgent inner joins

C LEFT OUTER join fetch or IEFT join fetch for an urgent right outer join

D The right outer join fetch, or join fetch, is used to urgently use outer joins

14. The right thing to say about Hibernate batch processing data is (CD).

A Batch operation with HQL, Hibernate does not support BULK INSERT

B Using the JDBC API for bulk operations, the data involved in SQL statements is loaded into the session cache, taking up memory space

C Use session for bulk operations, data will be loaded into session cache, attention should be paid to flush and empty cache

D Use session for batch operations, for complex business logic scenarios that require code processing

Explanation: Batch processing of data

Way One:
Using the HQL statement
Principle: Executeupdate
01. BULK INSERT Data
@Test
public void Testinsert () {
Session session = Hibernateutil.getsession ();
Transaction tx=session.begintransaction ();
String hql= "INSERT into Dept (deptname) Select D.deptname| | D.deptno from Dept D where d.deptno>0 ";
Session.createquery (HQL). Executeupdate ();
Tx.commit ();
}

Way two: Jdbcapi
Batch modification using the JDBC API
public void Testupdateusejdbc () {
Session session = Hibernateutil.getsession ();
Transaction tx=session.begintransaction ();
Work work=new () {
@Override
public void execute (Connection Connection) throws SQLException {
String sql= "Update depty2160new set deptname=? where Deptno>? ";
PreparedStatement PS = connection.preparestatement (SQL);
Ps.setstring (1, "Finance Department 2");
Ps.setint (2, 1);
Ps.executeupdate ();
}
};
Session.dowork (work);
Tx.commit ();
}


Method Three: Use Session for batch operation

public void Testadd () {
Session session = Hibernateutil.getsession ();
Transaction tx=session.begintransaction ();
EMP Emp=null;
for (int i = 0; i < 10000; i++) {
Emp=new EMP (i, "emp" +i);
Session.save (EMP);
if (i%30==0) {
Session.flush ();
Session.clear ();
}
}
Tx.commit ();
}

Little tip:
(1) using HQL for bulk operations database level executeupdate ()
(2) using the JDBC API for bulk operations database level
(3) Using session for batch operations will be cached


Little tip2:
C Use session for bulk operations, data will be loaded into session cache, attention should be paid to flush and empty cache
D Use session for batch operations, for complex business logic scenarios that require code processing

15. The use of aggregate functions for HQL is correct (ABCD).

A Select COUNT (*) from Dept D for Statistics Department number

B Select SUM (e.salary) from EMP E to summarize employee payroll

C Select Max (e.hiredate) from Emp E is used to find the entry time of the newest employee in the job

D Select min (e.hiredate) from Emp E to find the earliest entry time of the employee

Explanation: Hql for objects and properties, not tables and fields

16. In the HQL subquery, it is wrong to say (C).

A Size () or size to get the number of elements in the collection

B Elements () gets all the elements in the collection for the element

C The Any keyword is used for subquery statements to return all records

D The In keyword is the same as "=any"

17. For native SQL queries and named queries, the right thing to say is (ABC).

A To execute native SQL, use the SQLQuery object

B SQLQuery is an interface that inherits the query interface

C Hibernate supports the definition of query statements in the form of strings in a mapping file, such as a named query statement

D A named query statement can only be a HQL statement, not an SQL statement

Explanation: Native SQL queries and named queries

Query Query=session.createquery (HQL)
SQLQuery query=session.createsqlquery (SQL)

1. Native SQL queries
@Test
Native SQL execution
public void Testclassicsql () {
SQLQuery query = Session.createsqlquery ("SELECT * from Depty2160new"). Addentity (Dept.class);
list<dept> list = Query.list ();
for (Dept dept:list) {
System.out.println (Dept.getdeptname ());
}
Tx.commit ();
}


2. Named queries
<!---native SQL Nullpointexception--
<sql-query name= "Selectempbydetpnoclassicsql" >
<return alias= "E" class= "EMP" ></return>
Select {e.*} from Empy2160new e where deptno=:d Eptno
</sql-query>

Test class
public void Testnamedclassicsql () {
Query query = session.getnamedquery ("Selectempbydetpnoclassicsql");
list<emp> list = Query.setparameter ("DeptNo", 1). List ();
/* for (Emp emp:list) {
System.out.println (Emp.getempname ());
}*/
Tx.commit ();
}

18. In Hibernate, the method for mapping blobs and CLOB types in Oracle is correct (BCD).

A The CLOB type can only be mapped to java.lang.String

B Blob types can be mapped to Java.sql.Blob

C BLOB type can be mapped to byte[]

D Clob types can be mapped to java.lang.String or Java.sql.Clob

19. In hibernate, the argument about the criteria method is wrong (CD).

A The Restrictions.ge () method is equivalent to the HQL operator >=

B Restrictions.like ("EmpName", "s", Matchmode.start) methods are used to find employees whose names begin with S

C The Restrictions.disjunction () method is used to specify multiple logical AND

D The Restrictions.in () method can only be used for arrays

20. In hibernate, the annotation is correct (ABD).

A @Id the unique identity used to declare a persisted class, corresponding to the primary key in the data table

B @Cloumn used to map properties to columns

C @Transient used to ignore this property and need to persist to the database

D @GeneratedValue a build strategy for defining primary key values

Explanation: Hibernate common annotations

@Id
@Column
@Table
@Entity
@GeneratedValue
@ManyToOne
@JoinColumn

/** * Department class * @author Happy September 22, 2016 19:40:56 * */@Entity identifies a class that is a persisted class @table (name= "DeptY2160") public classDept {@Id The identity hibernate_session @GeneratedValue of the Persistence class (strategy=generationtype.sequence,generator= "Seq_gen"Define your own sequence generator @SequenceGenerator (name= "Seq_gen", sequencename= "Seq_num", allocationsize=1,initialvalue=1 private Integer deptNo; private String deptname; @OneToMany (mappedby= "dept", Cascade={ Cascadetype.all})/* @Fetch (Fetchmode.join) @LazyCollection (lazycollectionoption.false) */Private set<emp> Emps=new hashset<emp>(); public set<emp> Getemps () {return emps;} public void Setemps (Set<em P> emps) {this.emps = emps;} public Dept (Integer deptNo, String deptname) {this.deptno = deptNo; th Is.deptname = deptname;} public Dept () {} public Integer Getdeptno () {return deptNo;} public void< c15> Setdeptno (Integer deptNo) {this.deptno = deptNo;} public String Getdeptname () {return deptname;} p ublic void setdeptname (String deptname) {this.deptname = deptname;}}     

21. The following statement about synonyms, the correct option is (C).

A You can only create synonyms for a table, you cannot create a synonym for a view

B Synonyms can only be used to reference tables created by other users

C Public and private synonyms can have the same name as a table

D The table referenced by the synonym is not valid while deleting the synonym using the drop SYNONYM statement

Explain:

Primary key generation Policy
@GeneratedValue the generation strategy used to define the primary key value, equivalent to native

22. Evaluate the Create TABLE statement:

CREATE TABLE Products

(

PRODUCT_ID Number (6) CONSTRAINT prod_id_pk PRIMARY KEY,

Product_Name VARCHAR2 (15)

)

The following about the PROD_ID_PK option is correct (B).

A can be created, but requires a unique index to be created manually

B Can be created and will automatically create a unique index

C Can be created and will automatically create non-unique indexes

D can be created but cannot be used because no index is specified

23. The following SQL statement that creates the sequence:

CREATE SEQUENCE seq1

START with 100

INCREMENT by 10

MINVALUE 1

MAXVALUE 200

CYCLE

NOCACHE;

The generated value of the sequence seq1 has reached the maximum value of 200, and then executes the following statement:

SELECT Seq1.nextval from dual;

The options for the following explicit correct values are (A).

A 1

B 10

C 100

D Error

24. A_oe and A_HR are 2 users in the database, and there is a table orders under A_oe that executes the following statements:

CREATE ROLE R1; --system under

Grnat Select,insert on a_oe.orders to R1; --a_oe mode

GRANT R1 to A_hr; --system mode

GRANT SELECT on a_oe.orders to a_hr; --a_oe mode

REVOKE SELECT on a_oe.orders from A_HR;

The correct result after executing the above statement is (A).

A A_HR can query a_oe.orders table

B A_HR can not query a_oe.orders table

C The REVOKE statement revokes the A_HR SELECT permission and also revokes the SELECT permission from the R1 role

D The REVOKE statement will error because the SELECT permission has been granted by the R1 role

25. For the view, the following statement is correct (CD).

A Views with column aliases cannot be modified

B The use of subqueries in a complex view definition cannot contain aggregation (grouping) functions and joins

C If a view definition contains the DISTINCT keyword, it cannot be deleted through the view

D The or REPLACE option is used in the CREATE VIEW syntax to modify an existing view definition without deleting the view.

Second, Jane Answer (a total of 5 questions, 7.5 points per question)

1. Please briefly describe the relationship between hibernate and JDBC.

2. Please describe the difference between MyBatis and hibernate.

3. Please describe in detail how the three states of a Java object are converted in hibernate.

4. Please describe how hibernate is implemented for paging? If you do not use the method provided by hibernate to implement paging functionality, what is the way to page paging?

5. Write a canonical stored procedure according to the employee table. Complete the following tasks:

1). Pay the specified employee a raise, where the employee number and the rising wage amount are determined by the input parameters

2). Show all employee salary after pay rise

3). The following exceptions are considered in the stored procedure:

A A situation where the specified employee does not exist

B A situation where the wage increase is less than or equal to 0

4). Write a calling program that requires testing for various situations

Using hibernate to develop rental system internal test pen questions

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.