Jpa 消费者信用; this.callbackURL=callbackURL; this.requestToken=requestToken; this.tokenSecret=tokenSecret; this.accessToken=accessToken; 这个.授权的=授权的; this.accesTokenValidFrom=accesTokenValidFrom; this.roles=角色; } 公共整数getId(){ 返回此.id; } 公共无效集合id(整数id){ this.id=id; } 公共Idpuser getIdpuser(){ 返回此.idp用户; } 公共无效设置Idpuser(Idpuser Idpuser){ this.idpuser=idpuser; } 公共字符串getDescription(){ 返回此.description; } 公共void集合描述(字符串描述){ this.description=描述; } 公共字符串getConsumerKey(){ 把这个还给我; } public void setConsumerKey(字符串consumerKey){ this.consumerKey=consumerKey; } 公共字符串getConsumerCret(){ 返回此.ConsumerCret; } public void setConsumerCret(字符串ConsumerCret){ this.consumerSecret=consumerSecret; } 公共字符串getCallbackURL(){ 返回callbackURL; } public void setCallbackURL(字符串callbackURL){ this.callbackURL=callbackURL; } 公开日期getAccesTokenValidFrom(){ 返回accesTokenValidFrom; } 公共无效setAccesTokenValidFrom(日期accesTokenValidFrom){ this.accesTokenValidFrom=accesTokenValidFrom; } 公共字符串getAccessToken(){ 返回accessToken; } 公共无效setAccessToken(字符串accessToken){ this.accessToken=accessToken; } 公共整数getAccessTokenMaxUsageCount(){ 返回accessTokenMaxUsageCount; } public void setAccessTokenMaxUsageCount(整数accessTokenMaxUsageCount){ this.accessTokenMaxUsageCount=accessTokenMaxUsageCount; } 公共整数getAccessTokenNumUsageCount(){ 返回accessTokenNumUsageCount; } public void setAccessTokenNumSageCount(整数AccessTokenNumSageCount){ this.AccessTokenNumSageCount=AccessTokenNumSageCount; } 公共日期getAccessTokenValidTo(){ 返回accessTokenValidTo; } public void setAccessTokenValidTo(日期accessTokenValidTo){ this.accessTokenValidTo=accessTokenValidTo; } 公共布尔getAuthorized(){ 授权返回; } public void setAuthorized(Boolean authorized){ 这个.授权的=授权的; } 公共字符串getRequestToken(){ 返回请求令牌; } 公共无效setRequestToken(字符串requestToken){ this.requestToken=requestToken; } 公共字符串getTokenCret(){ 返回密码; } public void setTokenSecret(字符串tokenSecret){ this.tokenSecret=tokenSecret; } 公共集getRoles(){ 返回此.roles; } 公共无效集合角色(集合角色){ this.roles=角色; } 公共无效添加角色(角色r){ 这个.roles.add(r); } 公共无效清除器(角色r){ 此.roles.remove(r); } @凌驾 公共字符串toString(){ 返回此.description; } /*(非Javadoc) *@see java.lang.Object#hashCode() */ @凌驾 公共int hashCode(){ 最终整数素数=31; int结果=1; 结果=素数*结果 +((ConsumerCret==null)?0:ConsumerCret.hashCode(); 返回结果; } /*(非Javadoc) *@see java.lang.Object#equals(java.lang.Object) */ @凌驾 公共布尔等于(对象obj){ if(this==obj) 返回true; if(obj==null) 返回false; 如果(getClass()!=obj.getClass()) 返回false; 消费者其他=(消费者)obj; if(consumerSecret==null){ if(other.consumerSecret!=null) 返回false; }如果(!ConsumerCret.equals(other.ConsumerCret)) 返回false; 返回true; } /*听众处理*/ @短暂的 私有CopyOnWriteArrayList侦听器=新建CopyOnWriteArrayList(); 公共CopyOnWriteArrayList getListeners(){ 返回听众; } public void setListeners(CopyOnWriteArrayList侦听器){ this.listeners=侦听器; } public BigInteger getFacebookId(){ 返回facebookId; } 公共void setFacebookId(BigInteger facebookId){ this.facebookId=facebookId; } }
例外情况:Jpa 消费者信用; this.callbackURL=callbackURL; this.requestToken=requestToken; this.tokenSecret=tokenSecret; this.accessToken=accessToken; 这个.授权的=授权的; this.accesTokenValidFrom=accesTokenValidFrom; this.roles=角色; } 公共整数getId(){ 返回此.id; } 公共无效集合id(整数id){ this.id=id; } 公共Idpuser getIdpuser(){ 返回此.idp用户; } 公共无效设置Idpuser(Idpuser Idpuser){ this.idpuser=idpuser; } 公共字符串getDescription(){ 返回此.description; } 公共void集合描述(字符串描述){ this.description=描述; } 公共字符串getConsumerKey(){ 把这个还给我; } public void setConsumerKey(字符串consumerKey){ this.consumerKey=consumerKey; } 公共字符串getConsumerCret(){ 返回此.ConsumerCret; } public void setConsumerCret(字符串ConsumerCret){ this.consumerSecret=consumerSecret; } 公共字符串getCallbackURL(){ 返回callbackURL; } public void setCallbackURL(字符串callbackURL){ this.callbackURL=callbackURL; } 公开日期getAccesTokenValidFrom(){ 返回accesTokenValidFrom; } 公共无效setAccesTokenValidFrom(日期accesTokenValidFrom){ this.accesTokenValidFrom=accesTokenValidFrom; } 公共字符串getAccessToken(){ 返回accessToken; } 公共无效setAccessToken(字符串accessToken){ this.accessToken=accessToken; } 公共整数getAccessTokenMaxUsageCount(){ 返回accessTokenMaxUsageCount; } public void setAccessTokenMaxUsageCount(整数accessTokenMaxUsageCount){ this.accessTokenMaxUsageCount=accessTokenMaxUsageCount; } 公共整数getAccessTokenNumUsageCount(){ 返回accessTokenNumUsageCount; } public void setAccessTokenNumSageCount(整数AccessTokenNumSageCount){ this.AccessTokenNumSageCount=AccessTokenNumSageCount; } 公共日期getAccessTokenValidTo(){ 返回accessTokenValidTo; } public void setAccessTokenValidTo(日期accessTokenValidTo){ this.accessTokenValidTo=accessTokenValidTo; } 公共布尔getAuthorized(){ 授权返回; } public void setAuthorized(Boolean authorized){ 这个.授权的=授权的; } 公共字符串getRequestToken(){ 返回请求令牌; } 公共无效setRequestToken(字符串requestToken){ this.requestToken=requestToken; } 公共字符串getTokenCret(){ 返回密码; } public void setTokenSecret(字符串tokenSecret){ this.tokenSecret=tokenSecret; } 公共集getRoles(){ 返回此.roles; } 公共无效集合角色(集合角色){ this.roles=角色; } 公共无效添加角色(角色r){ 这个.roles.add(r); } 公共无效清除器(角色r){ 此.roles.remove(r); } @凌驾 公共字符串toString(){ 返回此.description; } /*(非Javadoc) *@see java.lang.Object#hashCode() */ @凌驾 公共int hashCode(){ 最终整数素数=31; int结果=1; 结果=素数*结果 +((ConsumerCret==null)?0:ConsumerCret.hashCode(); 返回结果; } /*(非Javadoc) *@see java.lang.Object#equals(java.lang.Object) */ @凌驾 公共布尔等于(对象obj){ if(this==obj) 返回true; if(obj==null) 返回false; 如果(getClass()!=obj.getClass()) 返回false; 消费者其他=(消费者)obj; if(consumerSecret==null){ if(other.consumerSecret!=null) 返回false; }如果(!ConsumerCret.equals(other.ConsumerCret)) 返回false; 返回true; } /*听众处理*/ @短暂的 私有CopyOnWriteArrayList侦听器=新建CopyOnWriteArrayList(); 公共CopyOnWriteArrayList getListeners(){ 返回听众; } public void setListeners(CopyOnWriteArrayList侦听器){ this.listeners=侦听器; } public BigInteger getFacebookId(){ 返回facebookId; } 公共void setFacebookId(BigInteger facebookId){ this.facebookId=facebookId; } },jpa,field,default,Jpa,Field,Default,例外情况: Dez 032011 12:58:21 PM org.hibernate.util.jdbceptionReporter logExceptions 警告:SQL错误:1364,SQLState:HY000 Dez 032011 12:58:21 PM org.hibernate.util.jdbceptionReporter logExceptions Schwerwiegend:字段“DescribeTion”没有默认值 线程“main”javax.persistence.Pe
Dez 032011 12:58:21 PM org.hibernate.util.jdbceptionReporter logExceptions
警告:SQL错误:1364,SQLState:HY000
Dez 032011 12:58:21 PM org.hibernate.util.jdbceptionReporter logExceptions
Schwerwiegend:字段“DescribeTion”没有默认值
线程“main”javax.persistence.PersistenceException:org.hibernate.Exception.genericjdbception:无法插入:[org.idp.persistence.mappings.Consumer]
位于org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1214)
位于org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1147)
位于org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1153)
位于org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:695)
位于org.idp.persistence.DataManager.saveOrUpdateEntity(DataManager.java:224)
位于org.idp.persistence.DataManager.saveOrUpdate(DataManager.java:142)
位于org.idp.persistence.mappings.Idpuser.addOrUpdateConsumer(Idpuser.java:259)
在org.idp.playdy.ReadTest.main(ReadTest.java:40)上
当我试图从数据库中读取数据时,它是有效的。当我尝试将数据插入另一个表(例如Idpuser)时,它也会起作用。我还尝试了以下解决方案建议:
<pre>
@SuppressWarnings("serial")
@Entity
@Table(name = "consumer", catalog = "oauth")
@NamedQueries({
@NamedQuery(name = Consumer.QUERY_BY_CONSUMER_KEY, query = "SELECT i FROM " + Consumer.TABLENAME + " i WHERE i.consumerKey = :" + Consumer.Q_PARAM_CONSUMER_KEY)})
public class Consumer implements java.io.Serializable {
public static final String TABLENAME = "Consumer";
public static final String QUERY_BY_CONSUMER_KEY = "ConsumerFindByConsumerKey";
public static final String Q_PARAM_CONSUMER_KEY = "consumer_key";
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
private Integer id;
@ManyToOne
@JoinColumn(name = "user_id", nullable = false)
private Idpuser idpuser;
@Column(name = "description", nullable = false, length = 500)
private String description;
@Column(name = "consumer_key", nullable = false, length = 100)
private String consumerKey;
@Column(name = "consumer_secret", nullable = false, length = 100)
private String consumerSecret;
@Column(name = "callbackurl", nullable = false, length = 400)
private String callbackURL;
@Column(name = "request_token", length = 500)
private String requestToken;
@Column(name = "token_secret", length = 500)
private String tokenSecret;
@Column(name = "access_token", length = 500)
private String accessToken;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "acces_token_valid_from", length = 19)
private Date accesTokenValidFrom;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "access_token_valid_to", length = 19)
private Date accessTokenValidTo;
@Column(name = "access_token_num_usage_count")
private Integer accessTokenNumUsageCount;
@Column(name = "access_token_max_usage_count")
private Integer accessTokenMaxUsageCount;
@Column(name = "authorized", nullable = false)
private Boolean authorized;
@ManyToMany(fetch= FetchType.EAGER)
@JoinTable(name = "consumer_role_relation",
joinColumns = {
@JoinColumn(name = "consumer_id")
},
inverseJoinColumns = {
@JoinColumn(name = "role_id")
}
)
private Set<Role> roles = new HashSet<Role>(0);
@Column(name = "facebookId", unique = true)
private BigInteger facebookId;
protected Consumer() {
}
public Consumer(Idpuser idpuser, String describtion, String consumerKey, String consumerSecret, String callbackURL,
String requestToken, String tokenSecret, String accessToken, boolean authorized) {
this.idpuser = idpuser;
this.description = describtion;
this.consumerKey = consumerKey;
this.consumerSecret = consumerSecret;
this.callbackURL = callbackURL;
this.requestToken = requestToken;
this.tokenSecret = tokenSecret;
this.accessToken = accessToken;
this.authorized = authorized;
}
public Consumer(Idpuser idpuser, String describtion, String consumerKey, String consumerSecret, String callbackURL,
String requestToken, String tokenSecret, String accessToken, boolean authorized,
Date accesTokenValidFrom, Date accessTokenValidTo, int accessTokenMaxUsageCount) {
this.idpuser = idpuser;
this.description = describtion;
this.consumerKey = consumerKey;
this.consumerSecret = consumerSecret;
this.callbackURL = callbackURL;
this.requestToken = requestToken;
this.tokenSecret = tokenSecret;
this.accessToken = accessToken;
this.authorized = authorized;
this.accesTokenValidFrom = accesTokenValidFrom;
this.accessTokenValidTo = accessTokenValidTo;
this.accessTokenMaxUsageCount = accessTokenMaxUsageCount;
}
public Consumer(Idpuser idpuser, String describtion, String consumerKey, String consumerSecret, String callbackURL,
String requestToken, String tokenSecret, String accessToken, boolean authorized,
Date accesTokenValidFrom, Date accessTokenValidTo, int accessTokenMaxUsageCount, Set<Role> roles) {
this.idpuser = idpuser;
this.description = describtion;
this.consumerKey = consumerKey;
this.consumerSecret = consumerSecret;
this.callbackURL = callbackURL;
this.requestToken = requestToken;
this.tokenSecret = tokenSecret;
this.accessToken = accessToken;
this.authorized = authorized;
this.accesTokenValidFrom = accesTokenValidFrom;
this.accessTokenValidTo = accessTokenValidTo;
this.accessTokenMaxUsageCount = accessTokenMaxUsageCount;
this.roles = roles;
}
public Consumer(Idpuser idpuser, String describtion, String consumerKey, String consumerSecret, String callbackURL,
String requestToken, String tokenSecret, String accessToken, boolean authorized,
Date accesTokenValidFrom, Date accessTokenValidTo) {
this.idpuser = idpuser;
this.description = describtion;
this.consumerKey = consumerKey;
this.consumerSecret = consumerSecret;
this.callbackURL = callbackURL;
this.requestToken = requestToken;
this.tokenSecret = tokenSecret;
this.accessToken = accessToken;
this.authorized = authorized;
this.accesTokenValidFrom = accesTokenValidFrom;
}
public Consumer(Idpuser idpuser, String describtion, String consumerKey, String consumerSecret, String callbackURL,
String requestToken, String tokenSecret, String accessToken, boolean authorized,
Date accesTokenValidFrom, Date accessTokenValidTo, Set<Role> roles) {
this.idpuser = idpuser;
this.description = describtion;
this.consumerKey = consumerKey;
this.consumerSecret = consumerSecret;
this.callbackURL = callbackURL;
this.requestToken = requestToken;
this.tokenSecret = tokenSecret;
this.accessToken = accessToken;
this.authorized = authorized;
this.accesTokenValidFrom = accesTokenValidFrom;
this.roles = roles;
}
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public Idpuser getIdpuser() {
return this.idpuser;
}
public void setIdpuser(Idpuser idpuser) {
this.idpuser = idpuser;
}
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
public String getConsumerKey() {
return this.consumerKey;
}
public void setConsumerKey(String consumerKey) {
this.consumerKey = consumerKey;
}
public String getConsumerSecret() {
return this.consumerSecret;
}
public void setConsumerSecret(String consumerSecret) {
this.consumerSecret = consumerSecret;
}
public String getCallbackURL() {
return callbackURL;
}
public void setCallbackURL(String callbackURL) {
this.callbackURL = callbackURL;
}
public Date getAccesTokenValidFrom() {
return accesTokenValidFrom;
}
public void setAccesTokenValidFrom(Date accesTokenValidFrom) {
this.accesTokenValidFrom = accesTokenValidFrom;
}
public String getAccessToken() {
return accessToken;
}
public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}
public Integer getAccessTokenMaxUsageCount() {
return accessTokenMaxUsageCount;
}
public void setAccessTokenMaxUsageCount(Integer accessTokenMaxUsageCount) {
this.accessTokenMaxUsageCount = accessTokenMaxUsageCount;
}
public Integer getAccessTokenNumUsageCount() {
return accessTokenNumUsageCount;
}
public void setAccessTokenNumUsageCount(Integer accessTokenNumUsageCount) {
this.accessTokenNumUsageCount = accessTokenNumUsageCount;
}
public Date getAccessTokenValidTo() {
return accessTokenValidTo;
}
public void setAccessTokenValidTo(Date accessTokenValidTo) {
this.accessTokenValidTo = accessTokenValidTo;
}
public Boolean getAuthorized() {
return authorized;
}
public void setAuthorized(Boolean authorized) {
this.authorized = authorized;
}
public String getRequestToken() {
return requestToken;
}
public void setRequestToken(String requestToken) {
this.requestToken = requestToken;
}
public String getTokenSecret() {
return tokenSecret;
}
public void setTokenSecret(String tokenSecret) {
this.tokenSecret = tokenSecret;
}
public Set<Role> getRoles(){
return this.roles;
}
public void setRoles(Set<Role> roles){
this.roles = roles;
}
public void addRole(Role r){
this.roles.add(r);
}
public void removeRole(Role r){
this.roles.remove(r);
}
@Override
public String toString(){
return this.description;
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((consumerSecret == null) ? 0 : consumerSecret.hashCode());
return result;
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Consumer other = (Consumer) obj;
if (consumerSecret == null) {
if (other.consumerSecret != null)
return false;
} else if (!consumerSecret.equals(other.consumerSecret))
return false;
return true;
}
/* ###### Listener handling ########################### */
@Transient
private CopyOnWriteArrayList<Object> listeners = new CopyOnWriteArrayList<Object>();
public CopyOnWriteArrayList<Object> getListeners() {
return listeners;
}
public void setListeners(CopyOnWriteArrayList<Object> listeners) {
this.listeners = listeners;
}
public BigInteger getFacebookId() {
return facebookId;
}
public void setFacebookId(BigInteger facebookId) {
this.facebookId = facebookId;
}
}
</pre>
<pre>
Dez 03, 2011 12:58:21 PM org.hibernate.util.JDBCExceptionReporter logExceptions
Warnung: SQL Error: 1364, SQLState: HY000
Dez 03, 2011 12:58:21 PM org.hibernate.util.JDBCExceptionReporter logExceptions
Schwerwiegend: Field 'describtion' doesn't have a default value
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not insert: [org.idp.persistence.mappings.Consumer]
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1214)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1147)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1153)
at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:695)
at org.idp.persistence.DataManager.saveOrUpdateEntity(DataManager.java:224)
at org.idp.persistence.DataManager.saveOrUpdate(DataManager.java:142)
at org.idp.persistence.mappings.Idpuser.addOrUpdateConsumer(Idpuser.java:259)
at org.idp.playground.ReadTest.main(ReadTest.java:40)
</pre>