JPA框架生成的SQL查询无法执行

时间:2015-04-30 11:49:33

标签: java sql oracle hibernate jpa

以下代码:

 public void edit(Routing routing) throws NonexistentEntityException, Exception {
    EntityManager em = null;
    try {
        em = getEntityManager();
        em.getTransaction().begin();
        routing = em.merge(routing);
        em.getTransaction().commit();
    } catch (Exception ex) {
        String msg = ex.getLocalizedMessage();
        if (msg == null || msg.length() == 0) {
            Long id = routing.getRoutingRuleId();
            if (findRouting(id) == null) {
                throw new NonexistentEntityException("The routing with id " + id + " no longer exists.");
            }
        }
        throw ex;
    } 

导致日志中出现以下错误:

2015-04-30 18:14:04,619 ERROR [ACTIVE] ExecuteThread:' 3' for queue:' weblogic.kernel.Default(自我调整)' com.xxx.yyy.admin.bean.RoutingManagerBean - 无法更新路由规则; org.eclipse.persistence.exceptions.DatabaseException:Internal Exception:java.sql.SQLSyntaxErrorException:ORA-00972:identifier太长

错误代码:972

通话:SELECT t1.ROUTING_RULE_ID,t1.BUSINESS_UNIT,t1.COUNTRY_DESC,t1.DANGEROUS_GOODS,t1.DESTINATION_ADDRESS_LOCATION,t1.DESTINATION_ADDRESS_TYPE,t1.DESTINATION_COUNTRY_DESC,t1.DESTINATION_STATE_DESC,t1.INDUSTRY_DESC,t1.ITEM_TYPE,t1.ITEM_WEIGHT, t1.ORIGIN_ADDRESS_LOCATION,t1.ORIGIN_ADDRESS_TYPE,t1.ORIGIN_COUNTRY_DESC,t1.ORIGIN_STATE_DESC,t1.SERVICE_DESC,t1.SERVICE_SUBTYPE_DESC,t1.SERVICE_TYPE_DESC,t1.STATE_DESC,t1.SUBJECT_DESC,t1.DESTINATION_CD FROM WP_ROUTING_WP_ROUTING T0,T1 WP_ROUTING WHERE((T0。 Routing_ROUTING_RULE_ID =?)AND(t1.ROUTING_RULE_ID = t0.routingDataList_ROUTING_RULE_ID))         bind => [1参数绑定]

查询:ReadAllQuery(名称=" routingDataList" referenceClass =路由SQL =" SELECT t1.ROUTING_RULE_ID,t1.BUSINESS_UNIT,t1.COUNTRY_DESC,t1.DANGEROUS_GOODS,t1.DESTINATION_ADDRESS_LOCATION,t1.DESTINATION_ADDRESS_TYPE ,t1.DESTINATION_COUNTRY_DESC,t1.DESTINATION_STATE_DESC,t1.INDUSTRY_DESC,t1.ITEM_TYPE,t1.ITEM_WEIGHT,t1.ORIGIN_ADDRESS_LOCATION,t1.ORIGIN_ADDRESS_TYPE,t1.ORIGIN_COUNTRY_DESC,t1.ORIGIN_STATE_DESC,t1.SERVICE_DESC,t1.SERVICE_SUBTYPE_DESC,t1.SERVICE_TYPE_DESC,T1 .STATE_DESC,t1.SUBJECT_DESC,t1.DESTINATION_CD FROM WP_ROUTING_WP_ROUTING T0,T1 WP_ROUTING WHERE((t0.Routing_ROUTING_RULE_ID =)AND(t1.ROUTING_RULE_ID = t0.routingDataList_ROUTING_RULE_ID)?)&#34)

以下是路由实体。

@Entity
@Table(name = "WP_ROUTING")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Routing.findAll", query = "SELECT rt FROM Routing rt"),
@NamedQuery(name = "Routing.findById", query = "SELECT rt FROM Routing rt    where (rt.routingRuleId = :ruleId)")})

public class Routing implements Serializable {

/**
 * Compare Routing Rules.
 */
public static final Comparator<Routing> COMPARE_BY_RULE = new CompareByRule();
public static final String DEFAULT_RULE_VALUE = "Any";

private static final long serialVersionUID = 0x9bc8875b3a917b08L;

@Id
@SequenceGenerator(name = "WP_ROUTING_ID_GENERATOR", sequenceName = "WP_ROUTING_ID_SEQ", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "WP_ROUTING_ID_GENERATOR")
@Basic(optional = false)
@Column(name = "ROUTING_RULE_ID")
private Long routingRuleId;

@Basic(optional = false)
@Column(name = "SUBJECT_DESC")
private String subjectDesc;

@Basic(optional = false)
@Column(name = "COUNTRY_DESC")
private String countryDesc;

@Basic(optional = false)
@Column(name = "STATE_DESC")
private String stateDesc;

@Basic(optional = false)
@Column(name = "SERVICE_DESC")
private String serviceDesc;

@Basic(optional = false)
@Column(name = "SERVICE_TYPE_DESC")
private String serviceTypeDesc;

@Basic(optional = false)
@Column(name = "SERVICE_SUBTYPE_DESC")
private String serviceSubtypeDesc;

@Basic(optional = false)
@Column(name = "INDUSTRY_DESC")
private String industryDesc;

@Basic(optional = false)
@Column(name = "ORIGIN_COUNTRY_DESC")
private String originCountryDesc;

@Basic(optional = false)
@Column(name = "ORIGIN_STATE_DESC")
private String originStateDesc;

@Basic(optional = false)
@Column(name = "DESTINATION_COUNTRY_DESC")
private String destinationCountryDesc;

@Basic(optional = false)
@Column(name = "DESTINATION_STATE_DESC")
private String destinationStateDesc;

@Basic(optional = false)
@Column(name = "ORIGIN_ADDRESS_TYPE")
private String originAddressType;

@Basic(optional = false)
@Column(name = "DESTINATION_ADDRESS_TYPE")
private String destinationAddressType;

@Basic(optional = false)
@Column(name = "ORIGIN_ADDRESS_LOCATION")
private String originAddressLocation;

@Basic(optional = false)
@Column(name = "DESTINATION_ADDRESS_LOCATION")
private String destinationAddressLocation;

@Basic(optional = false)
@Column(name = "DANGEROUS_GOODS")
private String dangerousGoods;

@Basic(optional = false)
@Column(name = "BUSINESS_UNIT")
private String businessUnit;

@Basic(optional = false)
@Column(name = "ITEM_TYPE")
private String itemType;

@Basic(optional = false)
@Column(name = "ITEM_WEIGHT")
private String itemWeight;

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "DESTINATION_CD", referencedColumnName = "DESTINATION_CD")
private Destination destination;

public Routing() {
}

public Routing(Long ident) {
    this.routingRuleId = ident;
}

public Long getRoutingRuleId() {
    return routingRuleId;
}

public void setRoutingRuleId(Long ident) {
    this.routingRuleId = ident;
}

public String getSubjectDesc() {
    return subjectDesc;
}

public void setSubjectDesc(String subject) {
    this.subjectDesc = subject;
}

public String getCountryDesc() {
    return countryDesc;
}

public void setCountryDesc(String country) {
    this.countryDesc = country;
}

public String getStateDesc() {
    return stateDesc;
}

public void setStateDesc(String state) {
    this.stateDesc = state;
}

public String getServiceDesc() {
    return serviceDesc;
}

public void setServiceDesc(String service) {
    this.serviceDesc = service;
}

public String getServiceTypeDesc() {
    return serviceTypeDesc;
}

public void setServiceTypeDesc(String type) {
    this.serviceTypeDesc = type;
}

public String getServiceSubtypeDesc() {
    return serviceSubtypeDesc;
}

public void setServiceSubtypeDesc(String subtype) {
    this.serviceSubtypeDesc = subtype;
}

public String getIndustryDesc() {
    return industryDesc;
}

public void setIndustryDesc(String industry) {
    this.industryDesc = industry;
}

public String getOriginCountryDesc() {
    return originCountryDesc;
}

public void setOriginCountryDesc(String originCountryDesc) {
    this.originCountryDesc = originCountryDesc;
}

public String getOriginStateDesc() {
    return originStateDesc;
}

public void setOriginStateDesc(String originStateDesc) {
    this.originStateDesc = originStateDesc;
}

public String getDestinationCountryDesc() {
    return destinationCountryDesc;
}

public void setDestinationCountryDesc(String country) {
    this.destinationCountryDesc = country;
}

public String getDestinationStateDesc() {
    return destinationStateDesc;
}

public void setDestinationStateDesc(String state) {
    this.destinationStateDesc = state;
}

public String getOriginAddressType() {
    return originAddressType;
}

public void setOriginAddressType(String type) {
    this.originAddressType = type;
}

public String getDestinationAddressType() {
    return destinationAddressType;
}

public void setDestinationAddressType(String type) {
    this.destinationAddressType = type;
}

public String getOriginAddressLocation() {
    return originAddressLocation;
}

public void setOriginAddressLocation(String location) {
    this.originAddressLocation = location;
}

public String getDestinationAddressLocation() {
    return destinationAddressLocation;
}

public void setDestinationAddressLocation(String location) {
    this.destinationAddressLocation = location;
}

public String getDangerousGoods() {
    return dangerousGoods;
}

public void setDangerousGoods(String dangerous) {
    this.dangerousGoods = dangerous;
}

public String getBusinessUnit() {
    return businessUnit;
}

public void setBusinessUnit(String unit) {
    this.businessUnit = unit;
}

public String getItemType() {
    return itemType;
}

public void setItemType(String type) {
    this.itemType = type;
}

public String getItemWeight() {
    return itemWeight;
}

public void setItemWeight(String weight) {
    this.itemWeight = weight;
}

public Destination getDestination() {
    return destination;
}

public void setDestination(Destination code) {
    this.destination = code;
}

@Override
public boolean equals(Object other) {
    if (other == this) {
        return true;

    } else if (other instanceof Routing) {
        final Routing that = (Routing) other;
        return new EqualsBuilder()
                .append(this.routingRuleId, that.routingRuleId)
                .isEquals();
    }
    return false;
}

@Override
public int hashCode() {
    return new HashCodeBuilder()
            .append(this.routingRuleId)
            .toHashCode();
}

@Override
public String toString() {
    return new ToStringBuilder(this)
            .append("routingRuleId", this.routingRuleId)
            .append("subjectDesc", this.subjectDesc)
            .append("countryDesc", this.countryDesc)
            .append("stateDesc", this.stateDesc)
            .append("serviceDesc", this.serviceDesc)
            .append("serviceTypeDesc", this.serviceTypeDesc)
            .append("serviceSubtypeDesc", this.serviceSubtypeDesc)
            .append("industryDesc", this.industryDesc)
            .append("originCountryDesc", this.originCountryDesc)
            .append("originStateDesc", this.originStateDesc)
            .append("destinationCountryDesc", this.destinationCountryDesc)
            .append("destinationStateDesc", this.destinationStateDesc)
            .append("originAddressType", this.originAddressType)
            .append("destinationAddressType", this.destinationAddressType)
            .append("originAddressLocation", this.originAddressLocation)
            .append("destinationAddressLocation", this.destinationAddressLocation)
            .append("dangerousGoods", this.dangerousGoods)
            .append("businessUnit", this.businessUnit)
            .append("itemType", this.itemType)
            .append("itemWeight", this.itemWeight)
            .append("destination", this.destination)
            .toString();
}

/**
 * Create a copy of a Routing object.
 *
 * @param req the Routing object to copy, may be null.
 * @return a new Routing object with all properties set the same as the req object, or null if req is null.
 */
public static Routing copyOf(Routing req) {
    if (req != null) {
        Routing result = new Routing(req.getRoutingRuleId());
        result.setSubjectDesc(req.getSubjectDesc());
        result.setCountryDesc(req.getCountryDesc());
        result.setStateDesc(req.getStateDesc());
        result.setServiceDesc(req.getServiceDesc());
        result.setServiceTypeDesc(req.getServiceTypeDesc());
        result.setServiceSubtypeDesc(req.getServiceSubtypeDesc());
        result.setIndustryDesc(req.getIndustryDesc());
        result.setOriginCountryDesc(req.getOriginCountryDesc());
        result.setOriginStateDesc(req.getOriginStateDesc());
        result.setDestinationCountryDesc(req.getDestinationCountryDesc());
        result.setDestinationStateDesc(req.getDestinationStateDesc());
        result.setOriginAddressType(req.getOriginAddressType());
        result.setDestinationAddressType(req.getDestinationAddressType());
        result.setOriginAddressLocation(req.getOriginAddressLocation());
        result.setDestinationAddressLocation(req.getDestinationAddressLocation());
        result.setDangerousGoods(req.getDangerousGoods());
        result.setBusinessUnit(req.getBusinessUnit());
        result.setItemType(req.getItemType());
        result.setItemWeight(req.getItemWeight());
        result.setDestination(req.getDestination());
        return result;
    }
    return null;
}

/**
 * Compare Routing Rules.
 */
private static final class CompareByRule implements Serializable, Comparator<Routing> {

    private static final long serialVersionUID = 0x5be0fa9fd1736d74L;
    private static final Comparator<String> COMPARE_ANY_FIRST = new CompareAnyFirst();

    @Override
    public int compare(Routing lhs, Routing rhs) {
        return new CompareToBuilder()
                .append(lhs.subjectDesc, rhs.subjectDesc, COMPARE_ANY_FIRST)
                .append(lhs.countryDesc, rhs.countryDesc, COMPARE_ANY_FIRST)
                .append(lhs.stateDesc, rhs.stateDesc, COMPARE_ANY_FIRST)
                .append(lhs.serviceDesc, rhs.serviceDesc, COMPARE_ANY_FIRST)
                .append(lhs.serviceTypeDesc, rhs.serviceTypeDesc, COMPARE_ANY_FIRST)
                .append(lhs.serviceSubtypeDesc, rhs.serviceSubtypeDesc, COMPARE_ANY_FIRST)
                .append(lhs.industryDesc, rhs.industryDesc, COMPARE_ANY_FIRST)
                .append(lhs.originCountryDesc, rhs.originCountryDesc, COMPARE_ANY_FIRST)
                .append(lhs.originStateDesc, rhs.originStateDesc, COMPARE_ANY_FIRST)
                .append(lhs.destinationCountryDesc, rhs.destinationCountryDesc, COMPARE_ANY_FIRST)
                .append(lhs.destinationStateDesc, rhs.destinationStateDesc, COMPARE_ANY_FIRST)
                .append(lhs.originAddressType, rhs.originAddressType, COMPARE_ANY_FIRST)
                .append(lhs.destinationAddressType, rhs.destinationAddressType, COMPARE_ANY_FIRST)
                .append(lhs.originAddressLocation, rhs.originAddressLocation, COMPARE_ANY_FIRST)
                .append(lhs.destinationAddressLocation, rhs.destinationAddressLocation, COMPARE_ANY_FIRST)
                .append(lhs.dangerousGoods, rhs.dangerousGoods, COMPARE_ANY_FIRST)
                .append(lhs.businessUnit, rhs.businessUnit, COMPARE_ANY_FIRST)
                .append(lhs.itemType, rhs.itemType, COMPARE_ANY_FIRST)
                .append(lhs.itemWeight, rhs.itemWeight, COMPARE_ANY_FIRST)
                .append(lhs.destination, rhs.destination, COMPARE_ANY_FIRST)
                .toComparison();
    }
}

/**
 * A case-insensitive String comparator that sorts the values null, blank, or "Any" before other values.
 */
private static final class CompareAnyFirst implements Serializable, Comparator<String> {

    private static final long serialVersionUID = 0x96afd43da5aa3ba9L;
    private static final String FIRST_VALUE = "aaaaaaaa";

    @Override
    public int compare(String lhs, String rhs) {
        String left = (StringUtils.isBlank(lhs) || lhs.equalsIgnoreCase(DEFAULT_RULE_VALUE)) ? FIRST_VALUE : lhs;
        String right = (StringUtils.isBlank(rhs) || rhs.equalsIgnoreCase(DEFAULT_RULE_VALUE)) ? FIRST_VALUE : rhs;

        return left.compareToIgnoreCase(right);
    }
}

}

请有人帮我解决这个问题。 似乎由JPA生成的sql查询不符合预期。 如果我修改查询以将表名更正为&#34; WP_ROUTING&#34;和列名&#34; ROUTING_RULE_ID&#34;并在sql开发人员中执行它工作正常。

先谢谢。

0 个答案:

没有答案