Win a copy of Java by Comparison (eBook) this week in the Java in General forum!

ajay mittal

Greenhorn
+ Follow
since Nov 23, 2011
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 ajay mittal

Hi All,

Can anyone help me out to know the difference between the following statements:-

1. String str = null;
String str = "";

2. str.equals(null);
null.equals(str);

Waiting for your valuable replies.

Ajay

4 years ago
Hi All,

I used the following statements in main function:-

System.out.println(Integer.MIN_VALUE);
System.out.println(-(Integer.MIN_VALUE));

Output:
-2147483648
-2147483648

While obtaining the negative of a negative number i am still getting a negative number. Can anyone let me know the reason for this behaviour.

regards,
Ajay
5 years ago
Hi All,

I resolved the issue, it was due to the HQL behaviour while dealing with EnumType in where clause.

I updated my HQL query to

Query query = hibSession.createQuery("from ActionDetails as ad where ad.id.fldCircleId="+circleId+" and ad.id.fldProfileId="+profileId+" and ad.id.elementType='"+elementType+"' and ad.id.actionId="+actionId);

from:
Query query = hibSession.createQuery("from ActionDetails as ad where ad.id.fldCircleId="+circleId+" and ad.id.fldProfileId="+profileId+" and ad.id.elementType="+elementType+" and ad.id.actionId="+actionId);

and the things were done for me.

Ajay
Hi All,

Please let me know the fix for this exception.

EXCEPTION:

ERROR: Unknown column 'FOLDER' in 'where clause'
org.hibernate.exception.SQLGrammarException: Unknown column 'FOLDER' in 'where clause'
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:82)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129)
at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
at $Proxy5.executeQuery(Unknown Source)
at org.hibernate.loader.Loader.getResultSet(Loader.java:2031)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1832)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1811)
at org.hibernate.loader.Loader.doQuery(Loader.java:899)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:341)
at org.hibernate.loader.Loader.doList(Loader.java:2516)
at org.hibernate.loader.Loader.doList(Loader.java:2502)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2332)
at org.hibernate.loader.Loader.list(Loader.java:2327)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:490)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355)
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:195)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1247)
at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)
at com.onmobile.doa.ActionDetailsDOA.fetchActionDetailsByCircleIdProfileIdElementTypeAndactionId(ActionDetailsDOA.java:24)
at com.onmobile.doa.ActionDetailsDOA.main(ActionDetailsDOA.java:41)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'FOLDER' in 'where clause'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1885)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122)
... 18 more

The DataModel sample is :

public class ActionDetails implements java.io.Serializable {

private static final long serialVersionUID = 1L;

private AId id; // containing composite primary key
private int parentId;
}

public class AId implements Serializable{
private int fldCircleId;
private int fldProfileId;
private ElementType elementType;
}

class Folder extends ActionDetails {
// contains attributes provided in ActionDetails.hbm.xml
}

class Item extends ActionDetails {
// contains attributes provided in ActionDetails.hbm.xml
}

The sample of ActionDetails.hbm.xml:

<hibernate-mapping>
<class name="com.onmobile.model.ActionDetails" table="action_details"catalog="selene2">
<composite-id name="id" class="model.ActionDetailsId">
<key-property name="fldCircleId" type="int">
<column name="fld_circle_id" />
</key-property>
<key-property name="fldProfileId" type="int">
<column name="fld_profile_id" />
</key-property>
<key-property name="elementType">
<column name="element_type" length="7" />
<type name="org.hibernate.type.EnumType">
<param name="enumClass">com.onmobile.model.ElementType</param>
<param name="type">12</param> <!-- 12 corresponds to java.sql.Types.VARCHAR -->
</type>
</key-property>
</composite-id>

<discriminator column="element_type" insert="false"/>


<property name="parentId" type="int">
<column name="parent_id" not-null="true" />
</property>
<property name="elementIndex" type="int">
<column name="element_index" not-null="true" />
</property>
<property name="level" type="int">
<column name="level" not-null="true" />
</property>
<property name="oldActionId" type="java.lang.Integer">
<column name="old_action_id" />
</property>
<property name="elementDetails" type="string">
<column name="element_details" length="1000" />
</property>

<set name="menuHighestActionIds" table="menu_highest_action_id" inverse="true" lazy="true" fetch="select">
<key>
<column name="fld_circle_id" not-null="true" />
<column name="fld_profile_id" not-null="true" />
<column name="element_type" length="7" not-null="true" />
<column name="highest_action_id" not-null="true" />
</key>
<one-to-many class="com.onmobile.model.MenuHighestActionId" />
</set>
<!-- Attributes of Folder.java -->

<subclass name="com.onmobile.model.Folder" discriminator-value="FOLDER">
<property name="folderId" type="java.lang.Integer">
<column name="folder_id" />
</property>
<property name="title" type="string">
<column name="title" length="20" />
</property>
</subclass>

<!-- Attributes of Item.java -->
<subclass name="com.onmobile.model.Item" discriminator-value="ITEM">
<property name="softId" type="java.lang.Integer">
<column name="softid" />
</property>
<property name="title" type="string">
<column name="title" length="20" />
</property>
<property name="description" type="string">
<column name="description" length="50" />
</property>
<property name="subscriptionInfo">
<column name="subscriptioninfo" length="35" />
<type name="org.hibernate.type.EnumType">
<param name="enumClass">com.onmobile.model.SubscriptionInfo</param>
<param name="type">12</param><!-- 12 corresponds to java.sql.Types.VARCHAR -->
</type>
</property>
<property name="commandType">
<column name="commandtype" length="13" />
<type name="org.hibernate.type.EnumType">
<param name="enumClass">com.onmobile.model.CommandType</param>
<param name="type">12</param> <!-- 12 corresponds to java.sql.Types.VARCHAR -->
</type>
</property>
<property name="keyword" type="string">
<column name="keyword" length="10" />
</property>
<property name="shortcode" type="java.lang.Integer">
<column name="shortcode" />
</property>
</subclass>
</class>
</hibernate-mapping>

The sample od ActionDetailsDOA.java :

public List<ActionDetails> fetchActionDetailsByCircleIdProfileIdElementTypeAndactionId(int circleId, int profileId, ElementType elementType, int actionId) throws Exception{
try{
hibSession = HibernateUtil.getSessionFactory().openSession();
tx = hibSession.beginTransaction();
Query query = hibSession.createQuery("from ActionDetails as ad where ad.id.fldCircleId="+circleId+" and ad.id.fldProfileId="+profileId+" and ad.id.elementType="+elementType+" and ad.id.actionId="+actionId);
System.out.println("AJAY");
List list = query.list();
System.out.println("MITTAL");
System.out.println(list);
tx.commit();
return null;
}catch(Exception exception){
tx.rollback();
throw exception;
}finally{
if(hibSession != null){
hibSession.close();
}
}
}

While using the above fetch API i am getting the exception mentioned above. The database i have used is mysql. I have mapped java Enumeration to varchar of mysql and it is inserting the rows properly. But while obtaining value from db it gives above exception. I think it is not able to map mysql varchar to java enumeration.
Sorry the DOA contains following application :

public List<ActionDetails> fetchActionDetailsByCircleIdProfileIdElementTypeAndactionId(int circleId, int profileId, ElementType elementType, int actionId) throws Exception{
try{
hibSession = HibernateUtil.getSessionFactory().openSession();
tx = hibSession.beginTransaction();
Query query = hibSession.createQuery("from ActionDetails as ad where ad.id.fldCircleId="+circleId+" and ad.id.fldProfileId="+profileId+" and ad.id.elementType="+elementType+" and ad.id.actionId="+actionId);
System.out.println("AJAY");
List list = query.list();
System.out.println("MITTAL");
System.out.println(list);
tx.commit();
return null;
}catch(Exception exception){
tx.rollback();
throw exception;
}finally{
if(hibSession != null){
hibSession.close();
}
}
}
Hi All,

Please let me know the fix for this exception.

EXCEPTION:

ERROR: Unknown column 'FOLDER' in 'where clause'
org.hibernate.exception.SQLGrammarException: Unknown column 'FOLDER' in 'where clause'
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:82)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129)
at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
at $Proxy5.executeQuery(Unknown Source)
at org.hibernate.loader.Loader.getResultSet(Loader.java:2031)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1832)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1811)
at org.hibernate.loader.Loader.doQuery(Loader.java:899)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:341)
at org.hibernate.loader.Loader.doList(Loader.java:2516)
at org.hibernate.loader.Loader.doList(Loader.java:2502)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2332)
at org.hibernate.loader.Loader.list(Loader.java:2327)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:490)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355)
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:195)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1247)
at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)
at com.onmobile.doa.ActionDetailsDOA.fetchActionDetailsByCircleIdProfileIdElementTypeAndactionId(ActionDetailsDOA.java:24)
at com.onmobile.doa.ActionDetailsDOA.main(ActionDetailsDOA.java:41)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'FOLDER' in 'where clause'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1885)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122)
... 18 more

The DataModel sample is :

public class ActionDetails implements java.io.Serializable {

private static final long serialVersionUID = 1L;

private AId id; // containing composite primary key
private int parentId;
}

public class AId implements Serializable{
private int fldCircleId;
private int fldProfileId;
private ElementType elementType;
}

class Folder extends ActionDetails {
// contains attributes provided in ActionDetails.hbm.xml
}

class Item extends ActionDetails {
// contains attributes provided in ActionDetails.hbm.xml
}

The sample of ActionDetails.hbm.xml:

<hibernate-mapping>
<class name="com.onmobile.model.ActionDetails" table="action_details"catalog="selene2">
<composite-id name="id" class="model.ActionDetailsId">
<key-property name="fldCircleId" type="int">
<column name="fld_circle_id" />
</key-property>
<key-property name="fldProfileId" type="int">
<column name="fld_profile_id" />
</key-property>
<key-property name="elementType">
<column name="element_type" length="7" />
<type name="org.hibernate.type.EnumType">
<param name="enumClass">com.onmobile.model.ElementType</param>
<param name="type">12</param> <!-- 12 corresponds to java.sql.Types.VARCHAR -->
</type>
</key-property>
</composite-id>

<discriminator column="element_type" insert="false"/>


<property name="parentId" type="int">
<column name="parent_id" not-null="true" />
</property>
<property name="elementIndex" type="int">
<column name="element_index" not-null="true" />
</property>
<property name="level" type="int">
<column name="level" not-null="true" />
</property>
<property name="oldActionId" type="java.lang.Integer">
<column name="old_action_id" />
</property>
<property name="elementDetails" type="string">
<column name="element_details" length="1000" />
</property>

<set name="menuHighestActionIds" table="menu_highest_action_id" inverse="true" lazy="true" fetch="select">
<key>
<column name="fld_circle_id" not-null="true" />
<column name="fld_profile_id" not-null="true" />
<column name="element_type" length="7" not-null="true" />
<column name="highest_action_id" not-null="true" />
</key>
<one-to-many class="com.onmobile.model.MenuHighestActionId" />
</set>
<!-- Attributes of Folder.java -->

<subclass name="com.onmobile.model.Folder" discriminator-value="FOLDER">
<property name="folderId" type="java.lang.Integer">
<column name="folder_id" />
</property>
<property name="title" type="string">
<column name="title" length="20" />
</property>
</subclass>

<!-- Attributes of Item.java -->
<subclass name="com.onmobile.model.Item" discriminator-value="ITEM">
<property name="softId" type="java.lang.Integer">
<column name="softid" />
</property>
<property name="title" type="string">
<column name="title" length="20" />
</property>
<property name="description" type="string">
<column name="description" length="50" />
</property>
<property name="subscriptionInfo">
<column name="subscriptioninfo" length="35" />
<type name="org.hibernate.type.EnumType">
<param name="enumClass">com.onmobile.model.SubscriptionInfo</param>
<param name="type">12</param><!-- 12 corresponds to java.sql.Types.VARCHAR -->
</type>
</property>
<property name="commandType">
<column name="commandtype" length="13" />
<type name="org.hibernate.type.EnumType">
<param name="enumClass">com.onmobile.model.CommandType</param>
<param name="type">12</param> <!-- 12 corresponds to java.sql.Types.VARCHAR -->
</type>
</property>
<property name="keyword" type="string">
<column name="keyword" length="10" />
</property>
<property name="shortcode" type="java.lang.Integer">
<column name="shortcode" />
</property>
</subclass>

</class>
</hibernate-mapping>

The sample od ActionDetailsDOA.java :

public List <MenuActionIdList> fetchMenuActionIdList(int circleId, int profileId, int majorVersion, int minorVersion) throws Exception{
try{
hibSession = HibernateUtil.getSessionFactory().openSession();
tx = hibSession.beginTransaction();

Query query = hibSession.createQuery("from MenuActionIdList as maidl where maidl.id.fldCircleId="+circleId+" and maidl.id.fldProfileId="+profileId+" and maidl.id.majorVersion="+majorVersion+" and maidl.id.minorVersion="+minorVersion);
List<com.onmobile.model.MenuActionIdList> mAIdList = query.list();
tx.commit();

return mAIdList;
}catch(Exception e){
tx.rollback();
throw e;
}finally{
if(hibSession != null){
hibSession.close();
}
}
}

While using the above fetch API i am getting the exception mentioned above. The database i have used is mysql. I have mapped java Enumeration to varchar of mysql and it is inserting the rows properly. But while obtaining value from db it gives above exception. I think it is not able to map mysql varchar to java enumeration.
Hi All,

Currently i am using ORM through hibernate in a project where i have two options while designing my data models and its mapping with db tables.

1. Create the data models a replica copy of tables in db, so that while using hibernate i can easily map each row to a object in java. but leads me to a large size of data in db. Which can be a performance hindrance parameter
after 1-2 years.

2. I can create data models by using my own explicit logic on objects obtained from db, in this case also i will use hibernate but i have to create my own new data models for internal functioning of application after using data from data models mapped to certain tables in db. This will even reduce size of my tables to a great extent and will not cause any performance hindrance but this will break the ORM pattern partially because it will give be objects but i have to convert them into one useful for my application logic.

Please suggest me the write approach to be used.

Regards,
Ajay
Hi Guys,

I have created a servlet whose both doGet and doPost method make call to a doProcess method. In this method i have fetched the parameters passed in URL and have even made checks for whether they are null or not. I have used a plugin of Lapse+ to determine vulnerability sources (security threats) as per java coding standards. While using the plugin it is showing PARAMETER TAMPERING for using request.getParameter(). Does anyone have a solution for it because as per java coding standards it is not a valid way to obtain values.

Regards,
Ajay
5 years ago
Hi All,

For what SERIAL_VERSION_UID meant for.

Ajay Mittal
6 years ago
Hi,

This is caused by directly refering to the login URL. Instead, you should go to a protected resource, such as Main.jsp. If login is required, this will redirect you to the login page. The "j_security_check" URL is a kind of temporary resource that only exists.if the tomcat decided that the login page should be shown.

For example -
if the protected resource is main.jsp

Then you should not specify the login.jsp in <welcome-file-list> in web.xml, instead you should specify the main.jsp.

Ajay Mittal
6 years ago

Paul Clapham wrote:The Thread.sleep(millis) method is the way to prevent a thread from doing anything for a certain period of time.




yes, i know this guys, but in this case i donot know that for how much time do i need to sleep. Is there any means to know when that when another application will get up.

Ajay Mittal
6 years ago
Hi all,
I have created a java application that is traced using log4j api. I want that each time the application is invoked a new log file should be generated with log file name as logfilename_currentdate_time using log4j.properties.

Help me out.

Ajay Mittal
6 years ago
Hi all,

I have created an application that has only main thread, this main thread calls the api of another application. Sometimes another application goes down this results in java.net.ConnectException. Due to which my application skips the entry and checks for another entry and call the api of another application for next entry. I want to block the execution of my application till another application becomes up.

Please tell me how can i achieve this.

Ajay Mittal.
6 years ago

Rob Spoor wrote:Use a DailyRollingFileAppender.



Thanks a lot, but can you help me to know that how can i append the name of the file passed at cmd prompt to the log file name using log4j.properties.

Ajay Mittal
6 years ago