aravind yarram

Greenhorn
+ Follow
since Mar 28, 2003
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 aravind yarram

Hi,

The following HQL is resulting in parsing error at count (1). The problem is at the numeric 1 I am using in the count function. If i use a column name instead of the constant, the query executes successfully. Is this a restriction of hibermate?

select count(1) from Csa c where c.equipment.equipmentType = 'MA'

Thanks for your help!

Hibernate version: 3.x
I guess the issues is that i am trying to open a current seesion before the begin of the transaction. I resolved this issues by demarcating the transactions in the session facade than in the DAO.

My new changed code looks like this

public Long createCsa(Csa csa) {
Session session = DAOFactory.getCsaSessionFactory().getCurrentSession();

Long id=null;

try {

id=(Long)session.save(csa);

}
catch (Exception e) {
//if (tx!=null) tx.rollback();
//System.out.println(e);
}
return id;
}

and the code in session facade looks lie this

Transaction tx=DAOFactory.getCsaSessionFactory().openSession().beginTransaction();

//call methods on various DAOs which constitue one logical unit fo work

tx.commit();

//tx.rollback() in case of exceptions
Hi all,

I am using the JTA as explained in the hibernate documentation. The documentation says that if there is no transaction currently started, a new transaction will be opened upon the call to "getCurrentSession" method. however, when i call the following method "createCsa", it is throwing "Current transaction is not in progress" exception under WAS 6.

I'd appreciate if someone help me resolve this!

Hibernate version: 3.x

Code between sessionFactory.openSession() and session.close():

public Long createCsa(Csa csa) {
Session session = DAOFactory.getCsaSessionFactory().getCurrentSession();
Transaction tx=null;
Long id=null;

try {
tx = session.beginTransaction();

id=(Long)session.save(csa);

tx.commit();
}
catch (Exception e) {
if (tx!=null) tx.rollback();
System.out.println(e);
}
return id;
}

Full stack trace of any exception that occurs:

[8/18/06 13:33:11:549 CDT] 00000043 WebApp E SRVE0026E: [Servlet Error]-[action]: org.hibernate.HibernateException: Current transaction is not in progress
at org.hibernate.context.JTASessionContext.currentSession(JTASessionContext.java:67)
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:508)
at cat.dds.csm.dao.CsaDAOImpl.createCsa(CsaDAOImpl.java:23)
at com.aravind.struts.action.LiteFormUserRegistrationAction.execute(LiteFormUserRegistrationAction.java:97)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
at javax.servlet.http.HttpServlet.service(HttpServlet.java(Compiled Code))
at javax.servlet.http.HttpServlet.service(HttpServlet.java(Compiled Code))
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java(Compiled Code))
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java(Compiled Code))
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:2905)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:220)
at com.ibm.ws.webcontainer.VirtualHost.handleRequest(VirtualHost.java:204)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java(Compiled Code))
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java(Compiled Code))
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java(Compiled Code))
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java(Compiled Code))
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java(Compiled Code))
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminaters(NewConnectionInitialReadCallback.java(Compiled Code))
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java(Compiled Code))
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java(Compiled Code))
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java(Compiled Code))
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java(Compiled Code))
at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java(Compiled Code))
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java(Compiled Code))

Name and version of the database you are using: Oracle 10g
Hi all,

I've a situation where my business key is a combination of properties of two persistent entities. I am not sure how to use the "natural-id" element to group them. Following should be my business key

csaType + csaStartDate + csaEndDate + serialNumber (from Equipment.hbm.xml)

I appreciate your help. Thank you in advance!

Hibernate version: 3.x

Mapping documents:

Csa.hbm.xml

<class name="Csa" table="CSA">
<id name="id" column="CSA_ID">
<generator class="native"/>
</id>
<property name="csaType" column="CSA_TYPE" type="string" not-null="true" length="2"/>
<property name="detailedCsaType" column="CSA_TYPE_DETAIL" type="string" not-null="true" length="20"/>
<property name="startingSmu" column="STARTING_SMU" type="double" not-null="true" precision="10" scale="2"/>
<property name="smuIndicator" column="SMU_INDICATOR" type="string" not-null="true" length="2"/>
<property name="equipmentDeliveryDate" column="EQUIP_DELIVERY_DATE" type="date" not-null="true" />
<property name="csaStartDate" column="CSA_START_DATE" type="date" not-null="true" />
<property name="csaEndDate" column="CSA_END_DATE" type="date" not-null="true" />
<component name="csaSourceInfo" class="CsaSource">
<property name="dealerCode" column="DEALER_CODE" type="string" not-null="true" length="6"/>
<property name="regionCode" column="REGION_CODE" type="string" not-null="true" length="5"/>
</component>
<component name="csaAuditInfo" class="AuditInfo">
<property name="enteredDate" column="ENTERED_DATE" type="date" not-null="true" />
<property name="committer" column="COMMITTER" type="string" not-null="true" length="10"/>
<property name="modifiedDate" column="MODIFIED_DATE" type="date" not-null="true" />
</component>
<many-to-one name="equipment" class="Equipment" column="FK_EQUIP_ID" cascade="all" unique="true"/>
</class>

Equipment.hbl.xml

<class name="Equipment" table="EQUIPMENT">
<id name="id" column="EQUIP_ID">
<generator class="native" />
</id>
<property name="equipmentType" column="EQUIP_TYPE" type="string" not-null="true" length="2"/>
<property name="serialNumber" column="SERIAL_NUM" type="string" not-null="true" length="20"/>
<property name="model" column="MODEL" type="string" not-null="true" length="10"/>
<property name="industryCode" column="INDUSTRY_CODE" type="string" not-null="true" length="2"/>
<property name="mode" column="MODES" type="string" not-null="true" length="1"/>
<one-to-one name="owningCsa" class="Csa" property-ref="equipment"/>
</class>

Name and version of the database you are using racle 10g
Hi all,

I want to add a unique constraint on multiple columns. Can someone please let me know how to do specify this in the mapping document (if at all we can). Also, how does hibernate report the unqiue constraint violation? Does it give the name of the constraint that has been violated?

I want the unique constraint to be on "csaType" and "equipmentDeliverDate" columns combined!

Thank you in advacne!

Hibernate version: 3.x

Mapping documents:

<hibernate-mapping>

<class name="Csa" table="CSA">

<id name="id" column="CSA_ID">
<generator class="native"/>
</id>
<property name="csaType" column="CSA_TYPE" type="string" not-null="true" length="2"/>
<property name="detailedCsaType" column="CSA_TYPE_DETAIL" type="string" not-null="true" length="20"/>
<property name="startingSmu" column="STARTING_SMU" type="double" not-null="true" precision="10" scale="2"/>
<property name="smuIndicator" column="SMU_INDICATOR" type="string" not-null="true" length="2"/>
<property name="equipmentDeliveryDate" column="EQUIP_DELIVERY_DATE" type="date" not-null="true" />
<property name="csaStartDate" column="CSA_START_DATE" type="date" not-null="true" />
<property name="csaEndDate" column="CSA_END_DATE" type="date" not-null="true" />

</class>

</hibernate-mapping>

Name and version of the database you are using:Oracle 10g
Hi all,

Here are my relationships
A CONTRACT is always assigned one and only one CONTRACT_TYPE (CSA Lite, PM)

A CONTRACT_TYPE is always associated with zero or more CONTRACTs

The CONTRACT_TYPE is a static list which will not change overtime. The problem I am facing is that I doesnt want to SAVE the Contract_Type for every contract the user enters. however I just want to verify that the contract type user has selected is in the list of contracttypes in the database. I am not sure how to model this. Any help is appreciated.

Thank you in advance!

Hibernate version: 3.0

Mapping documents:

<?xml version="1.0"?>
<hibernate-mapping package="com.dds.domain">

<class name="Contract">
<id name="id" column="ID">
<generator class="sequence">
<param name="sequence">HIBERNATE_SEQUENCE</param>
</generator>
</id>

<property name="date" column="DATE_SUBMITTED" type="date"/>

<many-to-one name="contractType" column="FK_CONTRACT_TYPE_ID" class="ContractType" />

</class>

</hibernate-mapping>
--------------------------------------------------------------------------------------

<?xml version="1.0"?>
<hibernate-mapping package="com.dds.domain">
<class name="ContractType" table="CONTRACT_TYPE">
<id name="id" column="ID" type="long">
<generator class="sequence">
<param name="sequence">HIBERNATE_SEQUENCE</param>
</generator>
</id>
</class>
</hibernate-mapping>

Contract and ContractType classes

public class Contract implements Serializable
{

private static final long serialVersionUID = -4266076966823864842L;
private long id;
private Date date;
private ContractType contractType;

public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public ContractType getContractType() {
return contractType;
}
public void setContractType(ContractType type) {
this.contractType = type;
}
}


public class ContractType implements Serializable {

private static final long serialVersionUID = 1L;
private long id;
private String name;

public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

Code between sessionFactory.openSession() and session.close():

Session ses=sFactory.openSession();
ContractType ct=new ContractType();
Contract co=new Contract();
ct.setName("CSA Lite");
co.setDate(new Date());
co.setContractType(ct);
ses.save(ct);
ses.save(co);
ses.flush();

Name and version of the database you are using: Oracle 10g
Hi All,

I want to use custom written conversion utility to convert the date time genrated from the default implementation. So, I have written the following custom conversion class

Error

DefaultValidationEventHandler: [ERROR]: Cannot format given Object as a Date
Location: obj: com.aravind.customdatetime.impl.CustomDateTypeImpl@7ff8e19c
javax.xml.bind.ValidationException
- with linked exception:
[com.sun.xml.bind.serializer.AbortSerializationException: Cannot format given Object as a Date]




Here is the custom bindings file





However, when i try to Marsahll I am getting the following exception, I am not sure why though. I'd be very thankful if you can help me fix this issue

Create a StrignReader out of the XML in the String

Reader is=new StringReader(xmlString)

parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",schemaFileLocation);
parser.setFeature( "http://apache.org/xml/features/validation/schema",true);
parser.setFeature("http://apache.org/xml/features/validation/schema",false);
parser.setContentHandler(yourContentHandler);
parser.setErrorHandler(yourErrorHandler);
parser.setFeature( "http://xml.org/sax/features/validation",VALIDATION);
parser.setFeature( "http://xml.org/sax/features/namespaces",true);
parser.setFeature("http://apache.org/xml/features/validation/schema",true);
parser.setFeature( "http://apache.org/xml/features/validation/schema-full-checking",true);
parser.setFeature("http://apache.org/xml/features/continue-after-fatal-error", false);
parser.setFeature("http://apache.org/xml/features/validation/dynamic", false);

parser.parse(new InputSource(is));
Hi,

I have authored one schema containing any element and anyAttribute. Following is the schema

--------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd = "http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.ibm.com" xmlns penContent="http://www.ibm.com">
<xsd:element name="opencontent">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="one" type="xsd:string"/>
<xsd:any minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:anyAttribute/>
</xsd:complexType>
</xsd:element>
</xsd:schema>
--------------------------------------------------------------------------

The following is the XML

--------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<OpenContent:opencontent xmlns:openContent= "http://www.ibm.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ibm.com OpenContent.xsd ">
<one>Hi</one>
<new namespace="##any">I am new element </new>
<flower/>
</OpenContent:opencontent>
--------------------------------------------------------------------------

When I am trying to validate it using the Xerces 2.5.x I am getting the followign error. It is able to capture the element content for the "<one>" element but it is throwing the following error at the "new" element

org.xml. sax. SAXParseException : cvc-complex-type.2.4.c: The matching
wildcard is strict, but no declaration can be found for element 'new'.


Following is the java code snippet



ANY HELP IS HIGLY APPRECIATED.

Thx in advance.

Edit Comment: Disabled smiles in this post.

- m
[ May 02, 2005: Message edited by: Madhav Lakkapragada ]
Hi all,

The following is the code I am using to check the validity of the date. It was working fine till December 30. However it started trowing the "java.lang.IllegalArgumentException" starting from dec 31st, 2004. I am not sure why. But if I comment the "calendar.setLenient(false)" everything works fine. Any help would be highly appreciated.


try
{
java.util.Calendar calendar = java.util.Calendar.getInstance();
calendar.setLenient(false);
calendar.set(1966, 10, 21);
calendar.getTime();//throws if invalid
}
catch(Exception e)
{
}
19 years ago
<?xml version = "1.0" encoding = "UTF-8"?>
<xsd:schema xmlns:xsd = "http://www.w3.org/2001/XMLSchema" elementFormDefault = "qualified">
<xsd:element name = "Response">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Contact" maxOccurs="unbounded" type="ContactType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="ContactType">
<xsd:sequence>
<xsd:element name = "Phone" maxOccurs = "1">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base = "xsd:string">
<xsd:attribute name = "group" use="required" type="xsd:integer"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
<xsd:element name = "Email" maxOccurs = "1">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base = "xsd:string">
<xsd:attribute name = "group" use="required" type="xsd:integer"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>