ayan sevi

Greenhorn
+ Follow
since Sep 21, 2006
Merit badge: grant badges
For More
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 ayan sevi

Were there any built-in JMX console available for the Websphere v6.1? I just want to know whether my MBean has been successfully registered in the MBeanServer and I'd like to view notifications of my MBean, but didn't know where could I see my MBeans. Something like Management console of Jboss.

How would I also enable viewing of Websphere MBeans using Jconsole?

Regards,
Bryan
16 years ago
Hi,

My project requires a JMX support for application monitoring. Can anyone give me some advice on what are the factors i need to consider and to include for application monitoring. Can you give me also some ideas on the design of this component or maybe some URL reference to JMX design or even URL of open-source projects which uses JMX will do also?

Thanks a lot
Problem solved.

I should not have called the session.clear() executed by flush() from my source. Session clear, cancels all your pending transactions. Thus, reference to previous object after clear() is already stale.

Cheers, bryan
Hi ranchers,

Just want to know that in Hibernate when is this error happens?

Caused by: org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:61)
at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:46)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:24)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2353)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2257)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2557)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:92)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.springframework.orm.hibernate3.HibernateTemplate$27.doInHibernate(HibernateTemplate.java:806)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:367)
at org.springframework.orm.hibernate3.HibernateTemplate.flush(HibernateTemplate.java:804)


Tried to look at the API, and it says

/**
* Thrown when a version number or timestamp check failed, indicating that the
* <tt>Session</tt> contained stale data (when using long transactions
* with versioning). Also occurs if we try delete or update a row that does
* not exist.<br>
* <br>
* Note that this exception often indicates that the user failed to specify the
* correct <tt>unsaved-value</tt> strategy for a class!

Did I miss something here? I was just trying to remove a persistent object and then add a new persistent object, wherein, both objects have the same superclass (@MappedSuperClass), there, I have the version field contain in the superclass. Is there anything wrong here?

Any help is appreciated. Thanks.
Anyone who has thoughts on this???
Is wrapper type overhead (creating the object) negligible, even if you're working for let's say hundreds of thousand of data? Quite not sure on this.
Hi,

Just a bit curious on this one, though I have also my own thoughts, since I'm new to ORM, I'd like to hear from you guys who have already gone through the ORM dev and design.

Imagine if I have a persistent class which represents a large table, let's say having 20 fields, is it better if I map this table to a SINGLE persistent class or make use of EMBEDDABLE class, somehow I extract some closely related fields and represent those field in another class, which is embeddable, though I cannot think of possible reuse on that embeddable class?

Thanks.
Hi,

Is there any significant factor why would I use Boolean over boolean for mapping fields in hibernate and the other way around, boolean over Boolean?

Or why would I use Wrapper types instead of primitives for mapping, and the other way around?

I got this post from javaranch Primitive vs. Wrapper mapping. Any other thoughts???

Thanks.
Great... , didn't know it works like that.

But when should we say in Hibernate, that your still on the same Unit of Work, or now your on a different one?

Is unit of work same as transaction?

Cheers
Hi,

Got a problem with hibernate lazy loading for one to many bidirectional relationship. Let's say I have the following class:

@Entity
public class User {

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;

@OneToMany(cascade={CascadeType.ALL}, fetch=FetchType.LAZY, mappedBy="user")
private List<Account> accounts;

....
}

@Entity
public class Account {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;

@ManyToOne
private User user;

....
}

and with the use of the following test case:

....
public void testCascadeUserAccount() {
// get User
User user = dao.get(1);
assertNotNull(user);
assertTrue(user.getId() == 1);

// add new account
Account account = newAccount();
account.setUser(user);
user.getAccounts().add(account); // OOPS! error was thrown here!!
dao.save(user);

assertTrue(user.getAccounts().size() == 3);

// check the list
List<Account> accounts = user.getAccounts();
assertNotNull(accounts);
for (Accounts a : accounts) {
log.debug("Account................" + a.toString());
assertTrue(a.getId() > 0);
}
}
....

An exception was thrown...

[emessaging] 2007-04-25 19:37:13 ERROR [main] LazyInitializationException.<init>(19) | failed to lazily initialize a collection of role: com.sample.model.User.accounts, no session or session was closed
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.sample.model.User.accounts, no session or session was closed
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350)
at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:97)
at org.hibernate.collection.PersistentBag.size(PersistentBag.java:225)
at com.g1.emessaging.dao.AccountDaoTest.testCascadeUserAccount(GatewayDaoTest.java:149)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:230)
at junit.framework.TestSuite.run(TestSuite.java:225)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:138)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:125)
at org.apache.maven.surefire.Surefire.run(Surefire.java:132)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:290)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:818)


but when I changed my test case into this, such that I queried again the user object to the database, and from there, assert that getAccounts().size() is equal to three, it runs fine.


....
public void testCascadeUserAccount() {
// get User
User user = dao.get(1);
assertNotNull(user);
assertTrue(user.getId() == 1);

// add new account
Account account = newAccount();
account.setUser(user);
//user.getAccounts().add(account); // OOPS! error was thrown here!!
dao.save(user);

//assertTrue(user.getAccounts().size() == 3); // this will also cause error when not commented

// code changes, to get again the modified user from the db
User modifiedUser = dao.get(1);
assertNotNull(modifiedUser);
assertEquals(modifiedUser.getAccounts().size() == 3);

// check the list
List<Account> accounts = user.getAccounts();
assertNotNull(accounts);
for (Accounts a : accounts) {
log.debug("Account................" + a.toString());
assertTrue(a.getId() > 0);
}
}
....



Does anyone has a clear explanation to this??

Thanks for your help....
Hi, hibernate newbie here. I'm having problem with the use of naming strategy, wherein according to hibernate docs, it should generate a foreign key column name with the format "name of the relationship in the owner side, _ (underscore), and the name of the primary key column(s) in the owned side", i.e. entity_id. When naming strategy was not specified leaving hibernate to use DefaultNamingStrategy, it behaves correctly, but when I tried to specify the naming strategy, this time with ImprovedNamingStrategy, it generates wrong column name, i.e. expected was "entity_id", it only generates "entity".

I'm using Maven2 plugin hbm2ddl for generating the schema.

Hibernate version: hibernate-3.2.1.ga, hibernate-annotation-3.2.1.ga

The generated SQL (show_sql=true):

alter table gateway_type_test
drop constraint FKB0101E3CA31F223D;

drop table gateway_test;

drop table gateway_type_test;

create table gateway_test (
id int identity not null,
name varchar(255) not null,
description varchar(255) null,
ssl tinyint not null,
port int not null,
user_name varchar(255) null,
password varchar(255) null,
sms_api_id varchar(255) null,
primary key (id)
);

create table gateway_type_test (
id int identity not null,
name varchar(255) not null,
gateway int null,
primary key (id)
);


alter table gateway_type_test
add constraint FKB0101E3CA31F223D
foreign key (gateway)
references gateway_test;



Thanks.
Got a workaround, see this link wsant task

Regards..., ayan
17 years ago
Does the ws ant task really needs to be run thru the ws_ant.bat?
I'm getting error running my ant script on ws ant task targets if I directly use the ant command.
Am I missing something here?

Regards.., ayan
17 years ago
Problem solved. A part of the code, which do not use the common utility for calling JNDI instead it calls directly to InitialContext for JNDI lookup.

Lessons learned.... lazy coder, be patient on tracing the error from the logs.



BTW, just one more question, is there any way to lookup JNDI directly without using the reference in the deployment descriptor (e.g. ejb-ref)?
I tried to called it directly just like this

// given the actual JNDI in the namespace was
// (top)/node......./servers/server01/jdbc/DS_MyApp
ctx.lookup("jdbc/DS_MyApp");

but it spits me out a NameNotFoundException. Any suggestion?

thanks..., bryan
17 years ago
Hi again,

I've been playing around with this JNDI reference unusual error for about more than a day but can't figured out why this problem occurred.

Here's the problem, when I tried to put the following nodes into my web xml, fortunately, I can access the said resource using java:comp/env reference:

<ejb-ref id="EjbRef_1">
<ejb-ref-name>docsense.AccessControlHome</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>com.docsense.core.ejb.AccessControl.AccessControlHome</home>
<remote>com.docsense.core.ejb.AccessControl.AccessControl</remote>
<ejb-link>CoreEJB.jar#AccessControlBean</ejb-link>
</ejb-ref>

corresponding ibm-web-bnd.xmi:

<ejbRefBindings xmi:id="EjbRefBinding_1172001538938" jndiName="ejb/AccessControlBean">
<bindingEjbRef href="WEB-INF/web.xml#EjbRef_1"/>
</ejbRefBindings>

But when I tried to register another reference of another EJB to the same web xml, shown below:

<ejb-ref id="EjbRef_2">
<ejb-ref-name>docsense.ProfileHome</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>com.docsense.core.ejb.Profile.ProfileHome</home>
<remote>com.docsense.core.ejb.Profile.Profile</remote>
<ejb-link>CoreEJB.jar#ProfileBean</ejb-link>
</ejb-ref>

corresponding ibm-web-bnd.xmi:

<ejbRefBindings xmi:id="EjbRefBinding_1172069350938" jndiName="ejb/ProfileBean">
<bindingEjbRef href="WEB-INF/web.xml#EjbRef_2"/>
</ejbRefBindings>

Its giving me a javax.naming.NameNotFoundException when I access the second resource, as shown in stack trace:

javax.naming.NameNotFoundException: Context: MND06100738Node01Cell/nodes/MND06100738Node01/servers/server1, name: docsense.ProfileHome: First component in name docsense.ProfileHome not found. [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL mg.org/CosNaming/NamingContext/NotFound:1.0]
at com.ibm.ws.naming.jndicos.CNContextImpl.processNotFoundException(CNContextImpl.java:4730)
at com.ibm.ws.naming.jndicos.CNContextImpl.doLookup(CNContextImpl.java:1907)
at com.ibm.ws.naming.jndicos.CNContextImpl.doLookup(CNContextImpl.java:1862)
at com.ibm.ws.naming.jndicos.CNContextImpl.lookupExt(CNContextImpl.java:1552)
at com.ibm.ws.naming.jndicos.CNContextImpl.lookup(CNContextImpl.java:1354)
at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:172)
at javax.naming.InitialContext.lookup(InitialContext.java:363)
at com.docsense.core.EjbUtil.getEjbHome(EjbUtil.java:111)
at com.docsense.core.mvc.MenuModel.refresh(MenuModel.java:139)
at com.docsense.core.mvc.MenuModel.<init>(MenuModel.java:78)
at com.docsense.core.mvc.Session.<init>(Session.java:57)
at com.docsense.core.mvc.HttpController.createSession(HttpController.java:724)
at com.docsense.core.mvc.HttpController.getSession(HttpController.java:643)
at com.docsense.core.mvc.HttpController.initSession(HttpController.java:553)
at com.docsense.core.mvc.HttpController.doPostAndGet(HttpController.java:279)
at com.docsense.core.mvc.HttpController.doGet(HttpController.java:192)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at com.ibm.ws.webcontainer.servlet.SingleThreadModelServlet.service(SingleThreadModelServlet.java:127)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:966)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:907)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:118)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:87)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:696)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:641)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:475)
at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:463)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3107)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:238)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:811)
at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1425)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:92)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:465)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:394)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:274)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:152)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:213)
at com.ibm.io.async.AbstractAsyncFuture.fireCompletionActions(AbstractAsyncFuture.java:195)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:193)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:725)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:847)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1498)
Caused by:
org.omg.CosNaming.NamingContextPackage.NotFound: IDL mg.org/CosNaming/NamingContext/NotFound:1.0
at com.ibm.ws.naming.ipcos.WsnOptimizedNamingImpl.do_resolve_complete_info(WsnOptimizedNamingImpl.java:543)
at com.ibm.ws.naming.cosbase.WsnOptimizedNamingImplBase.resolve_complete_info(WsnOptimizedNamingImplBase.java:2215)
at com.ibm.WsnOptimizedNaming._NamingContextStub.resolve_complete_info(_NamingContextStub.java:536)
at com.ibm.ws.naming.jndicos.CNContextImpl.cosResolve(CNContextImpl.java:4351)
at com.ibm.ws.naming.jndicos.CNContextImpl.doLookup(CNContextImpl.java:1901)
... 43 more

Here is an excerpt of namespace dump for reference:

....
24 (top)/nodes/MND06100738Node01/servers/server1/ejb/ProfileBean
25 (top)/nodes/MND06100738Node01/servers/server1/ejb/ivtEJBObject
26 (top)/nodes/MND06100738Node01/servers/server1/ejb/UserModelBean
27 (top)/nodes/MND06100738Node01/servers/server1/ejb/mgmt
28 (top)/nodes/MND06100738Node01/servers/server1/ejb/mgmt/MEJB
29 (top)/nodes/MND06100738Node01/servers/server1/ejb/AccessControlBean
....

What am I missing here? Does anyone here had already encountered the same problem?

Thanks in advance..., ayan
17 years ago