Tapan Maru

Ranch Hand
+ Follow
since May 08, 2006
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Tapan Maru

I was initializing the JComboBox today and observed it has a constructor which takes Vector as a parameter. Now according to a design standards, we should use interface type wherever possible so that at runtime, any implementation can be used. I have a question, is there any specific reason why JComboBox is using Vector as a parameter in the constructor instead of using List? What if I want to pass ArrayList or LinkedList while constructing the JComboBox?
4 years ago
Vector class in java has capacity method. My question is why it is not in any generic class like AbstractCollection so that any collection class can call that method to check current capacity?
8 years ago
My solution about ordinary use is --> Whenever GC thread runs, it will first identify all the objects for which there are no active reference present in the JVM. Suppose in the list of those objects, any particular object is used as a Key in WeakHashMap, the corresponding key-value pair will be removed from that WeakHashMap.

Please correct me if my understanding is not correct.

8 years ago
Thanks Piyush for the promt reply.

My code is as follows.

ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
Person p1 = (Person) context.getBean("a");
Person p2 = (Person) context.getBean("b");
System.out.println("P1 hash code = "+p1.hashCode());
System.out.println("P2 hash code = "+p2.hashCode());
System.out.println(p1 == p2);


Corrosponding XML is as follows.

<bean id="a" class="com.vaannila.Person"></bean>
<bean id="b" class="com.vaannila.Person"></bean>


When running the above code, I am getting 2 differeent hashcodes and also == returns false. Can you please help me explaining why it is?

"in case of singleton, multiple invocation returns you the same instance" - does it mean that multilple invocation of Person p1 = (Person) context.getBean("a"); will give me the same instance for every call if scope is Singleton and different instances if scope prototype?

Thanks
8 years ago
<idref bean="addr2"/>

Try out with the above code. Please share the resulets.

Thanks
8 years ago
Hi,

I am having a following declaration in Spring's bean file.

<bean id="a" class="com.vaannila.Person"></bean>
<bean id="b" class="com.vaannila.Person"></bean>

As I have not applied scope attribute, I expect only one instance will be created by spring for both the bean declarations.

But when I run the code, I got 2 different instances (one for each bean id) for the Persoan class having different hash codes.

I want to know how spring handles this kind of senario.
8 years ago
Thanks Sumeet.

Just one question from your answer.

<bean name="sessionBean" class="somepkg.SessionBean" scope="session">
<aop:scoped-proxy/>
</bean>

developer needs to take care of this or spring will take care of this?

my guess is developer needs to take care for this.

8 years ago
sorry but change in xml:


----------------- xml declaraion ----------------------------------------------------

<bean name="singletonBean" class="somepkg.SingletonBean">
<property name="someProperty" ref="sessionBean"/>
</bean>

<bean name="sessionBean" class="somepkg.SessionBean" scope="session"/>

------------------------------------------------------------------------------------------

Thanks,
8 years ago
Hi,

The default behavior for ApplicationContext implementations is to eagerly pre-instantiate all singleton beans at startup. Pre-instantiation means that an ApplicationContext will eagerly create and configure all of its singleton beans as part of its initialization process.

Now my xml file has following kind of bean declaration.

----------------- xml declaraion ----------------------------------------------------

<bean name="singletonBean" class="somepkg.SingletonBean">
<property name="someProperty" ref="sessionBean"/>
</bean>

<bean name="sessionBean" class="somepkg.SessionBean"/>

------------------------------------------------------------------------------------------

My doubts are:

1. Will singletonBean be able to initialize? or will it give any exception?
2. if singletonBean will be able to initialize, will spring instantiate sessionBean or not? because by default behavior, it is to be instantiate for each new session.
3. if sessionBean will be instantiated by spring, how it will again instantiate a new instance of that bean and give reference to singletonBean
4. if sessionBean will not be instantiated, will singletonBean contains a null reference of it after it is initialized or will it throw any exception and will not initialize at all.

8 years ago
Hi Jeanne,

Thanks for the reply. Yes I have also verified that Filter's init method is called on application startup by the container so no need to have load-on-startup kind of tag for it.

Thanks for Helping,

8 years ago
Why don't we have load-on-startup for Servlet filters as we have it for servlets?

8 years ago
Hello All,

Problem description:

I have a registerService which throws a RegistrationException if a username or email already exists in database.
On registration page, when user submits the form,I would like the user to see the message contained within the exception on the same page with the filled data, instead of forwarding them to an error page.

is this possible in spring?? if yes, how?

9 years ago
in the server.xml there is one proerty called crossContext. if you will set it to true, it allows the ServletContext.getContext() method to successfully return the ServletContext for other Web applications running in the same host.



9 years ago
Hi,

Can we have more than one class mappings in one hibernate mapping file?

lets say my module has 5 tables so can I logically group 5 class in one hibernate mapping file like the following?

<hibernate-mapping package="org.mypackage">

<class name="Class1" table="Table1">
---- column mappings goes here
</class>
<class name="Class2" table="Table2">
---- column mappings goes here
</class>
<class name="Class3" table="Table3">
---- column mappings goes here
</class>
<class name="Class4" table="Table4">
---- column mappings goes here
</class>
<class name="Class5" table="Table5">
---- column mappings goes here
</class>

</hibernate-mapping>



if we can declare like this, what is the advantage of such scenario?

Thanks

Tapan Maru
tapanmaru@gmail.com
Hi,

I am using hibernate at DAO layer with spring MVC in my application. As per my understandings we have to declare mapping resources (hibernate mapping files) in hibernate configuration file. What if my application needs addition of tables in future? Does it mean that I will have to add mapping resources in hibernate configuration file and redeploy the project again?

Is there any alternative solution so that I can avoid redeployment of the project?

Thanks in Advance..

Tapan Maru
tapanmaru@gmail.com