Kevin Cho

Greenhorn
+ Follow
since Nov 12, 2008
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Kevin Cho



From what I remember you want to use


create-drop will create tables and delete all tables when Spring Container is shutting down.

10 years ago

Mark Spritzler wrote:Let's make this a little easier.

1) What benefits do you get from extending a DaoSupport class? To me there is zero benefits, and one small disadvantage of coupling your code. Or if you think there are benefits, there are other ways to get the same benefit just as easy or easier without coupling your code.

Mark



That's exactly my point as well. I find it hard to believe that anyone would not have Spring coupling. If you make your DAO spring independent and use subjprojects like Spring MVC, Spring Security, Spring Integration... then I don't think it matters if you use DAO templates or not. My point is that, if your code already use any Spring Specfic feature then I think it's great to use the templates! In my DAO, I frequently tag w/ Spring Security annotations and Spring Cache... so should I not do that because it's adding more coupling? Still, I envy your work at SpringSource... I put in my resume but nope...!!! Anyways, I'm still going to stick w/ my belief ^_^
10 years ago
I'm a bit confused...

I assume you created that class to centralize Spring dependency. If so... I guess that's fine but why not utilize Sun's standar JSR250 and 330.

I forget the details but you can use JEE5 annotations instead of using Spring Annogations. Maybe I misunderstood your question.
10 years ago
I had no idea that even existed but now I know!

Still, I still recommend using Spring MVC Controller. Main reason being is the "testability"

void handleRequest(HttpServletRequest request, HttpServletResponse response)

With that signature it's really hard to execute JUnit for that. Also, you get convertion feature as well. For example if you pass URI "date=12-23-2011" then you can use the converter feature to "Date" directly w/o polluting your business logic. Of course, it's totally upto you but Spring MVC comes w/ Spring Core already and you can write JUnit tests against that. Just IMO.
10 years ago
There is a view in your case, it's XML
10 years ago
It sounds more like Spring MVC is the right solution. Don't think Spring MVC just outputs HTML file. After all who says JSP's can't be in xml format? It's just an output that's formatted by YOU. For example, many use SpringMVC RESTful Web Service that spits out XML. I've seen some people taking Spring OXM where it serializes Java -> XML. Do not think that MVC only spits out HTML. It can output whatever you printed out to be. I did see a Spring Subproject called Spring Flash or something I forget... I don't know how that one well but you may want to peek if that's better. Still, I am confident that SpringMVC will work fine.
10 years ago
I think I understand your question and yes there is a spring version of Servlets. They are SpringMVC.

You can use the @Controller to define a class that'll handle your HTTP traffic. It sounds like you want the back-end app to be written in SpringMVC.
10 years ago
Just going w/ what someone said to me.

IoC = You give the control to the container to get instance of objects. So instead of you doing "new", let the container do that for you.
DI = The act of "wiring" properties to an object.



10 years ago

Jeanne Boyarsky wrote:Kevin,
I think Amit's point is relevant. You used to be able to take the cert if you had experience. Now the only way to take it is by taking the course first. And no, I don't think the cert if valuable. I think they dumbed it down too much so it is more like a sign you paid attention in class.



Excellent! Thanks for the reply. That's what I figured too... It's sort of messed up that you can only take cert exam for those who took the course.
10 years ago
I agree that you learn it through the book then the manual. By all means, the manual is massive and very detailed!!! I guess it's like a Spring Bible. But it has so much details and texts... you get to miss the popular features that are commonly used. Spring In Action is definitely A+ for me but I like to add Spring Recipe 2.5 (not 3!!!). When I first started to use Spring, I felt like a deer caught in car's headlight but Spring Recipe 2.5 answered all my questions. After you read few books, I definitely would read over the documents. You'll find many "Oh~ I can also do it that way"
10 years ago
I never knew there would be disadvantages to IoC/DI... I would've said "What disadvantages?"

If one is having trouble understanding wiring configuration then it's probably not done right. Then again I can see some developers are getting carried away by putting all wirings through Spring. Also, using Annocations everywhere can be bad practices too. Maybe even go crazy with new Spring Expressions. Also, many Spring purist see any "new" or "extend" as an axis of evil. Do I really have to wire a bean that's "ArrayList" to assign to any class that has a "List"...seriously? They would create interface for every possible objects when they clearly know there will be one and only implementations. Then they say "This is good design by promoting interfaces and you can add new or change implementations later". It really does make good buzz words to the managers that it's good. Of course, 5 years later there is NO new implementation as we already knew.. Yes, it doesn't hurt to add 9999 interfaces but having 9999 java file that doesn't contain any benefits isn't common sense. I'm not saying I don't make interfaces for a single class. For example, if I want to utilize Mock frameworks then I will do so. Damn it... I'm getting off topic. I guess Spring DI can be crazy if one person "pre-optimizes the architecture" which makes it complex over some issues you'll never encounter.
10 years ago

Mark Spritzler wrote:1) No, you create a bean of type LocalSessionFactoryBean or AnnotationSessionFactoryBean to create a bean of type SessionFactory and in that bean set properties to set everything that you had had in the hibernate.cfg.xml

3) You will also need some of the Hibernate jars too.


2. I would have each of your DAO to extend HibernateDaoSupport. That class can has a field called hibernateTemplate which you can use for HQL.




Please please do not do this. If you make your DAO extend HibernateDaoSupport then your DAO is now tightly coupled with Spring. Spring itself does not want you to do this.

In the old days of Hibernate before Hibernate 3.1 and before Spring 2.5.6 this was a good idea. Now it is not, you will not gain anything by extending that class.

Make your DAO have a SessionFactory injected into it yourself. Then in the code call sessionFactory.getCurrentSession() to get a Session to run queries in. There is no more Hibernate boiler plate code to hide to even warrant using the HibernateTemplate.

Mark



That is a good solution as well. Yes, it's true that Spring itself doesn't want to be intrusive in your own code as well but I wouldn't rule it out. For examle, you can use JEE Annotations instead of using Spring Annotations but "with" limited feature. For example, if you want to use Cache Annotations and so forth. I think you're looking at a Spring Purist perspective ;) which is fine but in real world I don't see anyone trying to avoid Spring dependency. For example, if I'm using Spring MVC then should I still follow your approach? I'm already tied w/ Spring. Anyways, I'm 100% sure that I will NEVER switch to another DI then Spring. If there is any possibility of switching to other DI then your approach would make sense.

This kind of reminds me of using JPA instead of using Hibernate on one project and regret it Trying to implement findByExample in JPA was a pain in the ass...yes, I know new JPA spec has that now. Even with Hibernate, I still haven't encounter a case where someone said "Hibernate ORM sucks and we should use other ORM". Yes, I make sacrifice by tying Hibernate dependency in my own code but I gain additional functionalities that's not in JPA.
10 years ago

scott miles wrote:In most of the sites and books i have read two types os injection in spring that is

1)Constructor injection
2)Setter injection

As per my understanding autowiring is also a type of injection only. Is n't it? am i missing something here.



No, you're right. You're thinking too low level on how Spring does DI. It does it either though XML and Annotations. In XML, yes you do it through constructor or setter. In Annotations, you use @Autowired or other similar tags to wire other spring beans. So even at Annotation level you're either injecting through constructor or setter. Yes, you can use Annotation on constructor.

In annotation @Autowired through setter is like
@Autowired
private A a;

through constructor is like
public B(@Autowired a){
this.a = a;
}

Hope this make sense.
10 years ago

Amit Sharad wrote:Hi

There is a training that you have to attend, its a 4 full days long training 32 hrs , they do teach you some concepts that may not be covered in a book and then you can appear for an exam and like I mentioned before also by studying for a Core spring certification you would be learning many concepts in deep which eventually add to your knowledge. Even I have also worked on Spring 2x but now preparing for Spring 3x certification exam and I got to know some low level concepts of Spring as it is a very big framework and so many things to learn.



Thanks for that tip Amit but again that's not my question. Perhaps, I'm not communicating well with my words. From what I know training is one way to take certs but I've read that you can also take the certs if you're avid spring expert. Anyways, my question retains to the "value" of the certificate who has already been working w/ this technology for 6 years. Recently, I've landed a job where I simply answered few Spring related questions so I'm not even sure if it's worth getting this certificate. If this cert does have a significant value then I will absolutely get it!!!
10 years ago

Greg Funston wrote:Hi, I currently use Spring, Hibernate at work. I have never built my own Spring, Hibernate project from the ground up. This is what I am currently trying to do. There is a ton of information out there and I am reading everything I can. However, it is a lot of information and much of it is dated. I will keep reading and investigating to try to achieve my goal.

The Project

I wish to create a project using the spring framework with hibernate. My database of choice is MySQL(mostly because it is loaded and running on my server). I have the newest spring tools downloaded and my final objective is to create a link with hibernate and mysql. I am looking for advice on the best way to do this. My understanding so far is to use spring for most of the work. I welcome all opinions and look forward to the replies.

1. Is a hibernate.cfg.xml file required. If not is all the configuation done in the spring data-access-config.xml file?
2. If I want to use hql to communicate with hibernate and have it connect to SQL how is that best configured?
(My understanding is hibernate will translate to most databases abstracting the database to a jdbc connection).
3. What jar files will be needed to make this work?


Thank You.
Greg Funston



This is probably first reply to this forum... but I've been using Spring for a while now.

1. No, you don't need hibernate.cfg.xml as that can be configured in spring.
2. I would have each of your DAO to extend HibernateDaoSupport. That class can has a field called hibernateTemplate which you can use for HQL.
3. Just put everything you download for Spring core..I think it's around 20+. It really doesn't hurt unless you are really trying to save classloader memory.

Another advice...I've met many individuals recommending "Spring + Hibernate" because someone said so without understanding "why"... I know you're just doing the job told by some architect but really try to understand what Spring would benefit you by integrating with Hibernate. In short, the benefits of using Hibernate w/ Spring is that it handles the boilerplate code for you and making the DAO as "singletons" that can be wired easily on other Spring beans. For example, setting the SessionFactory. Also, Hibernate is technology that allows JDBC logics in Object Oriented Manner (well sort of since it has mysterious thing called HQL). Well, g'luck! I'm sure you'll get it working.
10 years ago