Professional Documents
Culture Documents
options.
update(): Will throw an exception if there is a persistent instance with the same
identifier.
lock(): Deprecated
replicate(): Persist the state of the given detached instance, reusing the current
identifier value.
merge(): Returns a persistent object with the same identifier. The given instance
does not become associated with the session.
Hence, lock() should not be used straightway and based on the functional
requirement one or more of them can be chosen.
JpaDao {
public void persist(E entity) {
if (entity.getId() == null) {
entityManager.persist(entity);
} else {
if (!entityManager.contains(entity)) {
entityManager.merge(entity);
}
}
}
}
req.getParameterValues("t1");
University(){
//Creating a university object depends on creating department objects.
//This indicates university is composed of depratments
departments = new Department()
}
}
SELECT *
FROM Employee Emp1
WHERE (N-1) = (
SELECT COUNT(DISTINCT(Emp2.Salary))
FROM Employee Emp2
WHERE Emp2.Salary > Emp1.Salary
)
public MyStack(int s) {
maxSize = s;
stackArray = new long[maxSize];
top = -1;
}
public void push(long j) {
stackArray[++top] = j;
}
public long pop() {
return stackArray[top--];
}
public long peek() {
return stackArray[top];
}
public boolean isEmpty() {
return (top == -1);
}
public boolean isFull() {
return (top == maxSize - 1);
}
public static void main(String[] args) {
MyStack theStack = new MyStack(10);
theStack.push(10);
theStack.push(20);
theStack.push(30);
theStack.push(40);
theStack.push(50);
while (!theStack.isEmpty()) {
long value = theStack.pop();
System.out.print(value);
System.out.print(" ");
}
System.out.println("");
}
}
@Override
public String findEmployeeName(int empId) {
@Override
public int findMaxSalary() {
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
@Test
public void testEquals_Symmetric() {
Person x = new Person("Foo Bar"); // equals and hashCode check name field
value
Person y = new Person("Foo Bar");
Assert.assertTrue(x.equals(y) && y.equals(x));
Assert.assertTrue(x.hashCode() == y.hashCode());
}
The serialization runtime associates with each serializable class a version number,
called a serialVersionUID, which is used during deserialization to verify
that the sender and receiver of a serialized object have loaded classes for that
object that are compatible with respect to serialization. If the receiver has
loaded a class for the object that has a different serialVersionUID than that of
the corresponding sender's class, then deserialization will result in an
InvalidClassException. A serializable class can declare its own serialVersionUID
explicitly by declaring a field named "serialVersionUID" that must be static,
final, and of type long:
Load : When ever the load() method is called, the hibernate creates a proxy object
of a POJO class, and it will set the id to the proxy object, then it returns
the proxy object to the program. Based on the operations performed on the proxy
object, the hibernate will decide whether to go cache or database to load the
data. This process is called lazy loading.
Get : When we call the get() method, then hibernate first goes to first level cache
and if that object doesnt exist in the first level cache then it goes to
database and loads the object from database. If Id doesnt exist in the database,
then get() method returns null. When get() method is called no proxy object
is created, hence it is called as early loading.
http://www.onlinetutorialspoint.com/hibernate/hibernate-session-differences-
between-load-and-get.html
https://joychakravarty.wordpress.com/spring/singleton-beans-with-prototype-bean-
dependencies/ read it