Tuesday, June 14, 2011

Spring-Hibernate major concerns for basics

@ManyToOne(cascade=CascadeType.PERSIST)
@ManyToOne(cascade=CascadeType.ALL)
@ManyToOne(cascade=CascadeType.MERGE)
@ManyToOne(cascade=CascadeType.REMOVE)
@ManyToOne(cascade=CascadeType.REFRESH)


@Transactional(propagation=Propagation.REQUIRED)
@Transactional(propagation=Propagation.SUPPORTS)

@RequestParam

Did you get the diff between when we are using hibernate solely and spring-hibernate as a combination?

Refer more...

There have many major differences with spring rather than normal hibernate.

Monday, June 13, 2011

what is the most special annotation for handling transactions in spring service layer?

@Transactional


And how should it be used when declaring read only and writing transactions?

@Service("businessUnitListService")
@Transactional(propagation=Propagation.SUPPORTS,readOnly=true)
public class BusinessUnitListServiceImpl implements BusinessUnitListService {


@Override
@Transactional(propagation=Propagation.SUPPORTS,readOnly=true)
public List getAllBusinessUnitList(Long businessUnitId) {
return businessUnitListDAO.getAllBusinessUnitList(businessUnitId);
}

@Override
@Transactional(propagation=Propagation.REQUIRED,readOnly=false)
public void deleteBusinessUnitList(String data) {
if (data.indexOf('[') > -1) {
List deleteBusinessUnitList = businessUnitListUtil.getListIdFromJSON(data);
for (Long id : deleteBusinessUnitList) {
businessUnitListDAO.deleteBusinessUnitList(id);
}
} else {
Long id = Long.parseLong(data.toString());
businessUnitListDAO.deleteBusinessUnitList(id);
}
}

}


if you missed out one of above annotation properly..

you will see only following sql statements on hibernate console
Hibernate: select businessun0_.BUSINESS_UNIT_ID as col_0_0_, businessun0_.CODE as col_1_0_, businessun0_.DESCRIPTION as col_2_0_ from transaction.BUSINESS_UNIT businessun0_
Hibernate: select nextval ('hibernate_sequence')

but data will not be inserted when it is a insert query..
if it was configured correctly.

you will see
Hibernate: select businessun0_.BUSINESS_UNIT_ID as col_0_0_, businessun0_.CODE as col_1_0_, businessun0_.DESCRIPTION as col_2_0_ from transaction.BUSINESS_UNIT businessun0_
Hibernate: select nextval ('hibernate_sequence')
Hibernate: insert into transaction.BUSINESS_UNIT_LIST (BUSINESS_UNIT_ID, CODE, DESCRIPTION, VERSION_ID, BUSINESS_UNIT_LIST_ID) values (?, ?, ?, ?, ?)

How do you define Spring based Junit classs?

@ContextConfiguration(locations="file:src/test/resources/ApplicationContext.xml")
@Transactional(propagation=Propagation.SUPPORTS,readOnly=true)
public class BusinessUnitListServiceImplTest extends AbstractTransactionalJUnit38SpringContextTests{
@BeforeClass
public static void setUpBeforeClass() throws Exception {
}

@AfterClass
public static void tearDownAfterClass() throws Exception {
}

@Before
protected void setUp() throws Exception {
super.setUp();
}

@After
protected void tearDown() throws Exception {
super.tearDown();
}

public void testAddBusinessUnitList(){
//your unit testings
}
}

Thursday, June 9, 2011

what are the objects types of hibernate?

1. Transient
2. Persistence
3. Detached

can final variable be assigned a value at runtime or compile time?

cannot

How can there be existed more than one object at runtime even we have used singleton pattern?

with "Reflection" it can be done.
http://en.wikipedia.org/wiki/Reflection_%28computer_science%29

I think I guess correctly but you are the decider which is the correct one????
hik hik....

just google it and find the answer.


code for learn something

public class A {

private static A a = null;

//singleton pattern
public static A getInstance(){
if(a==null)
a = new A();
return a;
}

void m(String msg){
System.out.println(msg);
}

public static void main(String[] args) {
A a = getInstance();
A.B b = a.new B();
a.m("m from A");
b.x(a);
}

class B{
void x(A a){
A t = A.getInstance();
t.m("x from B");
System.out.println("Both of objects are the same one? "+t.equals(a));
}
}

}

what is IOC and DI?

dependency injection is the passing or setting of dependencies into a software component.

DI is the most specific pattern of IOC.

want to know more -
follow this';;
http://martinfowler.com/articles/injection.html

The diff between jsp and servlet

JSP is used mainly for presentation only. A JSP can only be HttpServlet that means the only supported protocol in JSP is HTTP. But a servlet can support any protocol like HTTP, FTP, SMTP etc.




for more about jsp and servlets:::
http://www.javacertificate.net/jsp_iqns.htm

what are the autowiring scopes in spring?

just check here;;;

http://www.visualbuilder.com/java/spring/tutorial/autowiring-in-spring/

what is the treeSet in java?

This class implements the Set interface, backed by a TreeMap instance. This class guarantees that the sorted set will be in ascending element order, sorted according to the natural order of the elements (see Comparable), or by the comparator provided at set creation time, depending on which constructor is used.

java.lang.Object
extended by java.util.AbstractCollection
extended by java.util.AbstractSet
extended by java.util.TreeSet

For further reference:::::::

http://www.esus.com/docs/GetQuestionPage.jsp?uid=821

Java Dictionary and Collection API

Logical question- how can we handle corrupted xml errors or invalid data?

How can we handle errors which happening at run time when parsing an XML document through a web service? How can we detect specified error when XML was crashed or with invalid escape characters and keep record of that error to inform user?

?????????
?????
???
??
?

I guess the answer is here...
http://www.ibm.com/developerworks/library/x-saxerror/index.html

Diff of SAX and DOM

What is a transaction? what are the properties of a database transaction?

A transaction is an agreement, communication, or movement carried out between separate entities or objects,

ACID properties are related to database transaction.
1)atomic
2)consistent
3)isolated
4)durable

Difference between DTO and DAO...

DTO means Data Transfer Objects equivalent to POJO classess(Java beans) those are carrying data.

DAO means Data Access Objects those are doing CRUD operations with DTOs or DB

finally block

public class A {
public static void main(String[] args) {
System.out.println(new A().m());
}

public int m(){
try {
throw new Exception();
} catch (Exception e) {
return 0;
}finally{
return 1;
}
}
}

what will be the output of this????

Let's try to build scrum masters/project managers/software architects/even a company with training AI models

The concept: The basic concept is to build trained AI model for each role separately in scalable fashion within a private cloud. As an examp...