Myeclipse结合mysql和Jboss的EJB实体bean实例
2008-05-02 17:57
483 查看
演示地址:
http://d.download.csdn.net/fd3/aHR0cDovL2RsMi5jc2RuLm5ldC9kb3duMS8yMDA4MDUwMi8wMjE2MzA1MDQwNC5yYXI=!438865
说明: 分两部分,由于第一部分的演示有部分大家看了会不明白的,在第二部分进行了补充。
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import java.util.Properties;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import javax.naming.InitialContext;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import javax.naming.NamingException;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import com.SelectCourse;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import com.SelectCourseFacadeRemote;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
public class Test ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
/**//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @param args
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
public static void main(String[] args) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Properties props = new Properties();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
props.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
props.setProperty("java.naming.provider.url", "localhost:1099");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
InitialContext ctx;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
try ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ctx = new InitialContext(props);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
SelectCourseFacadeRemote remote = (SelectCourseFacadeRemote) ctx.lookup("SelectCourseFacade/remote");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
SelectCourse sc = new SelectCourse();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sc.setId((long)500);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sc.setCourseId(52);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sc.setStuId(533);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
remote.save(sc);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ctx.close();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
} catch (NamingException e) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println(e.getMessage());
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
} finally ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
persistence.xml
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<?xml version="1.0" encoding="UTF-8"?>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<persistence-unit name="myEjbEntityBean" transaction-type="JTA">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<jta-data-source>java:/DefaultMySqlDS</jta-data-source>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</persistence-unit>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</persistence>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
package com;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import javax.persistence.Column;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import javax.persistence.Entity;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import javax.persistence.Id;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import javax.persistence.Table;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
/**//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* SelectCourse entity.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
*
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @author MyEclipse Persistence Tools
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
@Entity
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
@Table(name = "select_course", catalog = "test", uniqueConstraints = ...{})
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
public class SelectCourse implements java.io.Serializable ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// Fields
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private Long id;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private Integer stuId;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private Integer courseId;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// Constructors
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
/**//** default constructor */
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
public SelectCourse() ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
/**//** minimal constructor */
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
public SelectCourse(Long id) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.id = id;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
/**//** full constructor */
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
public SelectCourse(Long id, Integer stuId, Integer courseId) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.id = id;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.stuId = stuId;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.courseId = courseId;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// Property accessors
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
@Id
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
@Column(name = "ID", unique = true, nullable = false, insertable = true, updatable = true)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
public Long getId() ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.id;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
public void setId(Long id) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.id = id;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
@Column(name = "stuId", unique = false, nullable = true, insertable = true, updatable = true)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
public Integer getStuId() ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.stuId;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
public void setStuId(Integer stuId) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.stuId = stuId;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
@Column(name = "courseId", unique = false, nullable = true, insertable = true, updatable = true)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
public Integer getCourseId() ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.courseId;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
public void setCourseId(Integer courseId) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.courseId = courseId;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
package com;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import java.util.List;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import javax.ejb.Remote;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
/**//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* Remote interface for SelectCourseFacade.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
*
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @author MyEclipse Persistence Tools
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
@Remote
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
public interface SelectCourseFacadeRemote ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
/**//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* Perform an initial save of a previously unsaved SelectCourse entity. All
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* subsequent persist actions of this entity should use the #update()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* method.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
*
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @param entity
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* SelectCourse entity to persist
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @throws RuntimeException
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* when the operation fails
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public void save(SelectCourse entity);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
/**//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* Delete a persistent SelectCourse entity.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
*
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @param entity
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* SelectCourse entity to delete
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @throws RuntimeException
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* when the operation fails
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public void delete(SelectCourse entity);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
/**//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* Persist a previously saved SelectCourse entity and return it or a copy of
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* it to the sender. A copy of the SelectCourse entity parameter is returned
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* when the JPA persistence mechanism has not previously been tracking the
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* updated entity.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
*
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @param entity
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* SelectCourse entity to update
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @returns SelectCourse the persisted SelectCourse entity instance, may not
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* be the same
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @throws RuntimeException
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* if the operation fails
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public SelectCourse update(SelectCourse entity);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public SelectCourse findById(Long id);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
/**//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* Find all SelectCourse entities with a specific property value.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
*
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @param propertyName
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* the name of the SelectCourse property to query
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @param value
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* the property value to match
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @param rowStartIdxAndCount
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* Optional int varargs. rowStartIdxAndCount[0] specifies the the
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* row index in the query result-set to begin collecting the
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* results. rowStartIdxAndCount[1] specifies the the maximum
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* count of results to return.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @return List<SelectCourse> found by query
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public List<SelectCourse> findByProperty(String propertyName, Object value,
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int... rowStartIdxAndCount);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public List<SelectCourse> findByStuId(Object stuId,
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int... rowStartIdxAndCount);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public List<SelectCourse> findByCourseId(Object courseId,
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int... rowStartIdxAndCount);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
/**//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* Find all SelectCourse entities.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
*
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @param rowStartIdxAndCount
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* Optional int varargs. rowStartIdxAndCount[0] specifies the the
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* row index in the query result-set to begin collecting the
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* results. rowStartIdxAndCount[1] specifies the the maximum
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* count of results to return.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @return List<SelectCourse> all SelectCourse entities
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public List<SelectCourse> findAll(int... rowStartIdxAndCount);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
package com;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import java.util.List;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import java.util.logging.Level;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import javax.ejb.Stateless;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import javax.persistence.EntityManager;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import javax.persistence.PersistenceContext;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import javax.persistence.Query;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
/**//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* Facade for entity SelectCourse.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
*
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @see com.SelectCourse
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @author MyEclipse Persistence Tools
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
@Stateless
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
public class SelectCourseFacade implements SelectCourseFacadeLocal,
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
SelectCourseFacadeRemote ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// property constants
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public static final String STU_ID = "stuId";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public static final String COURSE_ID = "courseId";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
@PersistenceContext
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private EntityManager entityManager;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
/**//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* Perform an initial save of a previously unsaved SelectCourse entity. All
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* subsequent persist actions of this entity should use the #update()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* method.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
*
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @param entity
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* SelectCourse entity to persist
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @throws RuntimeException
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* when the operation fails
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
public void save(SelectCourse entity) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
LogUtil.log("saving SelectCourse instance", Level.INFO, null);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
try ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
entityManager.persist(entity);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
LogUtil.log("save successful", Level.INFO, null);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
} catch (RuntimeException re) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
LogUtil.log("save failed", Level.SEVERE, re);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
throw re;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
/**//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* Delete a persistent SelectCourse entity.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
*
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @param entity
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* SelectCourse entity to delete
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @throws RuntimeException
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* when the operation fails
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
public void delete(SelectCourse entity) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
LogUtil.log("deleting SelectCourse instance", Level.INFO, null);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
try ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
entity = entityManager.getReference(SelectCourse.class, entity
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
.getId());
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
entityManager.remove(entity);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
LogUtil.log("delete successful", Level.INFO, null);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
} catch (RuntimeException re) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
LogUtil.log("delete failed", Level.SEVERE, re);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
throw re;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
/**//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* Persist a previously saved SelectCourse entity and return it or a copy of
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* it to the sender. A copy of the SelectCourse entity parameter is returned
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* when the JPA persistence mechanism has not previously been tracking the
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* updated entity.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
*
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @param entity
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* SelectCourse entity to update
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @returns SelectCourse the persisted SelectCourse entity instance, may not
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* be the same
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @throws RuntimeException
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* if the operation fails
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
public SelectCourse update(SelectCourse entity) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
LogUtil.log("updating SelectCourse instance", Level.INFO, null);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
try ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
SelectCourse result = entityManager.merge(entity);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
LogUtil.log("update successful", Level.INFO, null);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return result;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
} catch (RuntimeException re) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
LogUtil.log("update failed", Level.SEVERE, re);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
throw re;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
public SelectCourse findById(Long id) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
LogUtil.log("finding SelectCourse instance with id: " + id, Level.INFO,
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
null);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
try ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
SelectCourse instance = entityManager.find(SelectCourse.class, id);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return instance;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
} catch (RuntimeException re) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
LogUtil.log("find failed", Level.SEVERE, re);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
throw re;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
/**//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* Find all SelectCourse entities with a specific property value.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
*
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @param propertyName
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* the name of the SelectCourse property to query
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @param value
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* the property value to match
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @param rowStartIdxAndCount
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* Optional int varargs. rowStartIdxAndCount[0] specifies the the
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* row index in the query result-set to begin collecting the
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* results. rowStartIdxAndCount[1] specifies the the maximum
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* number of results to return.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @return List<SelectCourse> found by query
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
@SuppressWarnings("unchecked")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public List<SelectCourse> findByProperty(String propertyName,
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
final Object value, final int... rowStartIdxAndCount) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
LogUtil.log("finding SelectCourse instance with property: "
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
+ propertyName + ", value: " + value, Level.INFO, null);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
try ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
final String queryString = "select model from SelectCourse model where model."
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
+ propertyName + "= :propertyValue";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Query query = entityManager.createQuery(queryString);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
query.setParameter("propertyValue", value);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if (rowStartIdxAndCount != null && rowStartIdxAndCount.length > 0) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int rowStartIdx = Math.max(0, rowStartIdxAndCount[0]);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if (rowStartIdx > 0) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
query.setFirstResult(rowStartIdx);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if (rowStartIdxAndCount.length > 1) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int rowCount = Math.max(0, rowStartIdxAndCount[1]);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if (rowCount > 0) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
query.setMaxResults(rowCount);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return query.getResultList();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
} catch (RuntimeException re) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
LogUtil.log("find by property name failed", Level.SEVERE, re);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
throw re;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public List<SelectCourse> findByStuId(Object stuId,
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
int... rowStartIdxAndCount) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return findByProperty(STU_ID, stuId, rowStartIdxAndCount);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public List<SelectCourse> findByCourseId(Object courseId,
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
int... rowStartIdxAndCount) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return findByProperty(COURSE_ID, courseId, rowStartIdxAndCount);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
/**//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* Find all SelectCourse entities.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
*
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @param rowStartIdxAndCount
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* Optional int varargs. rowStartIdxAndCount[0] specifies the the
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* row index in the query result-set to begin collecting the
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* results. rowStartIdxAndCount[1] specifies the the maximum
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* count of results to return.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @return List<SelectCourse> all SelectCourse entities
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
@SuppressWarnings("unchecked")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
public List<SelectCourse> findAll(final int... rowStartIdxAndCount) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
LogUtil.log("finding all SelectCourse instances", Level.INFO, null);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
try ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
final String queryString = "select model from SelectCourse model";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Query query = entityManager.createQuery(queryString);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if (rowStartIdxAndCount != null && rowStartIdxAndCount.length > 0) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int rowStartIdx = Math.max(0, rowStartIdxAndCount[0]);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if (rowStartIdx > 0) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
query.setFirstResult(rowStartIdx);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if (rowStartIdxAndCount.length > 1) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int rowCount = Math.max(0, rowStartIdxAndCount[1]);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if (rowCount > 0) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
query.setMaxResults(rowCount);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return query.getResultList();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
} catch (RuntimeException re) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
LogUtil.log("find all failed", Level.SEVERE, re);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
throw re;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
mysql-ds.xml
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<?xml version="1.0" encoding="UTF-8"?>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<datasources>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<local-tx-datasource>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<jndi-name>DefaultMySqlDS</jndi-name>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<connection-url>jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=GBK
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</connection-url>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<driver-class>org.gjt.mm.mysql.Driver</driver-class>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<user-name>root</user-name>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<password>admin</password>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<metadata>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<type-mapping>mySQL</type-mapping>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</metadata>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</local-tx-datasource>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</datasources>
测试通过
相关文章推荐
- JBoss+Ant实现EJB无状态会话bean实例
- JBoss+Ant实现EJB无状态会话bean实例
- JBoss+Ant实现EJB无状态会话bean实例
- ejb jboss myeclipse 环境搭建 工程实例
- Mac下MyEclipse2015安装JBoss7,MySQL,EJB开发
- Myeclipse开发EJB3.0(实体bean)
- EJB 配置jboss 数据源 及 对数据库映射的实体Bean
- jboss4.2 webogic9.0 下,ejb2.0 实体bean主键的配置
- myeclipse+jboss开发EJB3.0之实体Bean
- eclipse + JBoss 5 + EJB3开发指南(11):实体Bean的连接策略(JOINED Strategy)
- Ubuntu系统下,Myeclipse+Jboss-as-7.1.1.Final配置MySQL
- jboss 下MySql DataSource EJB 部署问题
- JBoss+MyEclipse+Mysql 的J2EE环境配置
- 利用JBOSS+MyEclipse完成一个简单的EJB示例
- 连接mysql的javabean实例+简单分页
- JBOSS AS 7 客户端使用JNDI远程调用EJB Bean (方式之一)
- EJB---->实体bean
- JBOSS7搭载EJB3之实体Bean
- Mysql中DATE_SUB 使用方法结合查询一天内,一周内,一月内的信息实例讲解
- ejb的事务与实体bean