Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Transactional read only

 
pankaj semwal
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi List[],
The read is only for read operation (I mean it is used for select but not insert).

But when it calls the insert method its inserting the data.Which i think it should not be.

Please let me know where i am wrong.

however my code is declare like this:
And xml look like



 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it should through an exception.

Just a small note you only need

<tx:transaction-driven/>

Since it automatically creates proxies, and your transactionManager is called transactionManager, which is the default value for that property.

Mark
 
pankaj semwal
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,
When i use this <tx:annotation-driven />.I get exception
Exception in thread "main" java.lang.ClassCastException: $Proxy5 cannot be cast to com.Sem.MyDAO
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pankaj semwal wrote:Hi Mark,
When i use this <tx:annotation-driven />.I get exception
Exception in thread "main" java.lang.ClassCastException: $Proxy5 cannot be cast to com.Sem.MyDAO


You should change your code to create an interface for that class then have your DAO implement that class. It is best Java practice or best OO practice to code to interfaces, and Spring really want you to have interfaces to make it all run smoothly. So Spring actually forces you into that best practice.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic