• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to pull data using Spring frame work, Hibernate, and JPA from MS Sql Server 2000

 
nav katoch
Ranch Hand
Posts: 246
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Team,

Anybody has ever tried to pull data using spring, hibernate, jpa from MS Sql Server 2000 but It's working fine with Oracle.

Please let me know, then I will post the exact stuff on the forum.

Thanks and regards,

Naveen Katoch
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is indeed being done on many enterprise servers. You're not blazing any new ground here, I assure you.

What is the issue you are running into?

-Cameron McKenzie
 
nav katoch
Ranch Hand
Posts: 246
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks so much for your quick response. I appreciate it. I will post my stuff with some issues.

Thanks again,

Naveen
 
nav katoch
Ranch Hand
Posts: 246
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Below is the class file:-TbEngagementVDAO

package com.cpwr.stb.persistence.cp.dao;
// default package

import com.cpwr.stb.persistence.cp.entity.TbEngagementV;
import com.cpwr.stb.persistence.cp.entity.TbEngagementVId;
import com.cpwr.stb.utility.MessageFactory;

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceException;
import javax.persistence.Query;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.jpa.JpaCallback;
import org.springframework.orm.jpa.support.JpaDaoSupport;

/**
* A data access object (DAO) providing persistence and search support for
* TbEngagementV entities. Transaction control of the save(), update() and delete()
* operations can directly support Spring container-managed transactions or they
* can be augmented to handle user-managed Spring transactions. Each of these
* methods provides additional information for how to configure it for the
* desired type of transaction control.
*
* @see .TbEngagementV
* @author MyEclipse Persistence Tools
*/

public class TbEngagementVDAO extends JpaDaoSupport implements ITbEngagementVDAO {
// property constants
public static final String NAME = "name";
public static final String BILLING_MANAGER_ID = "billingManagerId";
public static final String ENGAGEMENT_STATUS_DESC = "engagementStatusDesc";
public static final String BILLING_OFFICE_ID = "billingOfficeId";
public static final String BILLING_CURRENCY = "billingCurrency";
public static final String PAYMENT_TERMS = "paymentTerms";
public static final String UDF_CODE_ID = "udfCodeId";
public static final String UDF_CODE_TITLE = "udfCodeTitle";
public static final String UDF_CODE_VALUE = "udfCodeValue";
public static final String UDF_TEXT_TITLE = "udfTextTitle";
public static final String UDF_TEXT_VALUE = "udfTextValue";

/*
* New DAO methods Added by Nitya Ganesh
*/


@SuppressWarnings("unchecked")
public List<TbEngagementV> findLikeName(final String customerId,
final String token) {
logger.info("findLikeName: Finding TbEngagementV records with customerId: "
+ customerId + ", name: " + token);
MessageFactory messageFactory = new MessageFactory();
final int maxRows = Integer.parseInt((String)messageFactory.getMessage("typeahead.max_rows"));

try {
String tmpQueryString = "select model from TbEngagementV model where lower(model.name) like lower(:value)";
if (customerId != null){
tmpQueryString +=" and model.CUSTOMER_ID = :customerId";
}
tmpQueryString += " order by CUSTOMER_ID, ENGAGEMENT_ID";
final String queryString = tmpQueryString;
return getJpaTemplate().executeFind(new JpaCallback() {
// TODO - check if this part needs to be changed
public Object doInJpa(EntityManager em)
throws PersistenceException {
Query query = em.createQuery(queryString);
query.setParameter("value", token);
if (customerId != null) query.setParameter("customerId", customerId);
query.setMaxResults(maxRows + 1);
return query.getResultList();
}
});
} catch (RuntimeException re) {
logger.error("find by name failed", re);
throw re;
}
}

}


persistence.xml
<persistence-unit name="stabMSSQLPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>

<class>com.cpwr.stb.persistence.cp.entity.TbEngagementV</class>
<class>com.cpwr.stb.persistence.cp.entity.TbEngagementVId</class>
<class>com.cpwr.stb.persistence.cp.entity.TbProjectV</class>
<class>com.cpwr.stb.persistence.cp.entity.TbProjectVId</class>
<class>com.cpwr.stb.persistence.cp.entity.TbCustomerV</class>
<class>com.cpwr.stb.persistence.cp.entity.TbTaskV</class>
<class>com.cpwr.stb.persistence.cp.entity.TbResourceV</class>
<class>com.cpwr.stb.persistence.cp.entity.TbTaskAssignmentV</class>
<properties>
<property name="hibernate.connection.driver_class" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<property name="hibernate.connection.url" value="jdbc:sqlserver://dtw-chgptsql1:1433"/>
<property name="hibernate.connection.username" value="stabtest"/>
<property name="hibernate.connection.password" value="test"/>
<property name="hibernate.show_sql" value="true"/>
</properties>
</persistence-unit>



<bean id="engagementService"
class="com.cpwr.stb.service.cp.EngagementService"
abstract="false"
lazy-init="default" autowire="no" dependency-check="default">
<!-- property name="engagementDAO"
ref="EngagementDAO" /> -->
<property name="seEmpGlAccessCtrlVService" ref="seEmpGlAccessCtrlVService"></property>
<property name="tbEngagementVDAO"
ref="TbEngagementVDAO" />
</bean>



It's not returning any data here. Do I need any settings anywhere else? Your help and suggestion will highly be appreciated.

query.setMaxResults(maxRows + 1);
return query.getResultList();

Cameron, I will eagerly wait for your fruitful comments and feedback.

Thank you very much

naveen katoch
 
Edison Gualberto
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have an article regarding spring transactions on JPA
http://www.ideyatech.com/2008/09/troubleshooting-tips-spring-transactions-on-jpa/
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic