- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我已经找到了多个与我的问题非常相似的问题,但遗憾的是,没有一个解决方案对我有帮助。
我需要表 Calendar 和 Day 之间的多对一关系。一个日历可以有多天。
这是我的代码,感谢您查看:
日历类:
@Entity
@Table(name="calendars")
@NamedQuery(name="Calendar.findAll", query="SELECT c FROM Calendar c")
public class Calendar implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name="calendar_id")
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int calendarId;
private String background;
@Temporal(TemporalType.DATE)
private Date begindate;
日历 bean :
@EJB
CalendarEJB calendarEJB;
private static final long serialVersionUID = 1L;
private String calendarName;
private int calendarID;
public String getCalendarName() {
return calendarName;
}
public void setCalendarName(String calendarName) {
this.calendarName = calendarName;
}
public int getCalendarID() {
return calendarID;
}
public void setCalendarID(int calendarID) {
this.calendarID = calendarID;
}
日间类(class):
@Entity
@Table(name="days")
@NamedQuery(name="Day.findAll", query="SELECT d FROM Day d")
public class Day implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private int iddays;
private int calendars_calendar_id;
//bi-directional many-to-one association to Calendar
@ManyToOne
@JoinColumn(name="calendar_id")
private Calendar calendar;
public int getCalendars_calendar_id() {
return calendars_calendar_id;
}
public void setCalendars_calendar_id(int calendars_calendar_id) {
this.calendars_calendar_id = calendars_calendar_id;
}
天 bean :
@EJB
DayEJB dayEJB;
private static final long serialVersionUID = 1L;
private int iddays;
private int calendars_calendar_id;
private CalendarBean calendarb = new CalendarBean();
public int getIddays() {
return iddays;
}
public void setIddays(int iddays) {
this.iddays = iddays;
}
public int getCalendars_calendar_id() {
return calendars_calendar_id;
}
public void setCalendars_calendar_id(int calendars_calendar_id) {
this.calendars_calendar_id = calendars_calendar_id;
}
public List<Day> allDays(){
return dayEJB.listAllDays();
}
数据库:
CREATE TABLE IF NOT EXISTS `mydb`.`calendars` (
`calendar_id` INT(5) NOT NULL AUTO_INCREMENT,
`calendarname` VARCHAR(45) NULL DEFAULT NULL,
`background` BLOB NULL DEFAULT NULL,
`begindate` DATE NULL DEFAULT NULL,
`public` TINYINT(1) NULL DEFAULT NULL,
PRIMARY KEY (`calendar_id`),
UNIQUE INDEX `calender_id_UNIQUE` (`calendar_id` ASC))
ENGINE = InnoDB
AUTO_INCREMENT = 121
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `mydb`.`days`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`days` (
`iddays` INT(10) NOT NULL AUTO_INCREMENT,
`date` VARCHAR(45) NULL DEFAULT NULL,
`text` VARCHAR(450) NULL DEFAULT NULL,
`link` VARCHAR(45) NULL DEFAULT NULL,
`calendars_calendar_id` INT(5) NOT NULL,
PRIMARY KEY (`iddays`),
INDEX `calendar_id_idx` (`calendars_calendar_id` ASC),
CONSTRAINT `calendar_id`
FOREIGN KEY (`calendars_calendar_id`)
REFERENCES `mydb`.`calendars` (`calendar_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
AUTO_INCREMENT = 8
DEFAULT CHARACTER SET = utf8;
我将@JoinColumn(name="calendar_id") 更改为外键名称但错误仍然存在,所以我将外键重命名为该值也没有变化。如果我将 @JoinColumn(name="calendar_id") 重命名为 calendars_calendar_id wildfly 根本无法部署。
控制台:
Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:80) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:89) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.loader.Loader.getResultSet(Loader.java:2065) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1862) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1838) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.loader.Loader.doQuery(Loader.java:909) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:354) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.loader.Loader.doList(Loader.java:2553) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.loader.Loader.doList(Loader.java:2539) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2369) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.loader.Loader.list(Loader.java:2364) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:496) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:387) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:231) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1264) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.internal.QueryImpl.list(QueryImpl.java:103) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:573) [hibernate-entitymanager-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:449) [hibernate-entitymanager-4.3.5.Final.jar:4.3.5.Final]
... 133 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'day0_.calendar_id' in 'field list'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.8.0_25]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) [rt.jar:1.8.0_25]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [rt.jar:1.8.0_25]
at java.lang.reflect.Constructor.newInstance(Constructor.java:408) [rt.jar:1.8.0_25]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:377)
at com.mysql.jdbc.Util.getInstance(Util.java:360)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:978)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3887)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3823)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2435)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2530)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1907)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2030)
at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:462)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:80) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
... 149 more
这里是重命名@joincolumn 时的 wildfly 控制台:
12:29:45,739 WARN [org.jboss.as.jpa] (DeploymentScanner-threads - 1) JBAS011411: Unexpected problem gathering statistics: java.lang.IllegalStateException: JBAS011477: Persistence unit 'Calendar-2dv012.war#Calendar-2dv012' is not available
at org.jboss.as.jpa.management.EntityManagerFactoryLookup.entityManagerFactory(EntityManagerFactoryLookup.java:44)
at org.jboss.as.jpa.hibernate4.management.HibernateEntityStatistics.getDynamicChildrenNames(HibernateEntityStatistics.java:145)
at org.jboss.as.jpa.management.DynamicManagementStatisticsResource.getChildren(DynamicManagementStatisticsResource.java:204)
at org.jboss.as.controller.registry.AbstractModelResource$DelegateResource.getChildren(AbstractModelResource.java:254) [wildfly-controller-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.controller.registry.Resource$Tools.readModel(Resource.java:252) [wildfly-controller-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.controller.registry.Resource$Tools.readModel(Resource.java:239) [wildfly-controller-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.controller.registry.Resource$Tools.readModel(Resource.java:225) [wildfly-controller-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.controller.registry.Resource$Tools.readModel(Resource.java:254) [wildfly-controller-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.controller.registry.Resource$Tools.readModel(Resource.java:239) [wildfly-controller-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.controller.registry.Resource$Tools.readModel(Resource.java:225) [wildfly-controller-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.controller.registry.Resource$Tools.readModel(Resource.java:254) [wildfly-controller-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.controller.registry.Resource$Tools.readModel(Resource.java:239) [wildfly-controller-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.controller.registry.Resource$Tools.readModel(Resource.java:225) [wildfly-controller-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.controller.registry.Resource$Tools.readModel(Resource.java:254) [wildfly-controller-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.controller.registry.Resource$Tools.readModel(Resource.java:239) [wildfly-controller-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.controller.registry.Resource$Tools.readModel(Resource.java:225) [wildfly-controller-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.controller.registry.Resource$Tools.readModel(Resource.java:213) [wildfly-controller-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.controller.ModelControllerImpl.writeModel(ModelControllerImpl.java:575) [wildfly-controller-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.controller.OperationContextImpl.createPersistenceResource(OperationContextImpl.java:224) [wildfly-controller-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.controller.AbstractOperationContext.doCompleteStep(AbstractOperationContext.java:526) [wildfly-controller-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.controller.AbstractOperationContext.completeStepInternal(AbstractOperationContext.java:281) [wildfly-controller-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.controller.AbstractOperationContext.finishStep(AbstractOperationContext.java:698) [wildfly-controller-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.controller.AbstractOperationContext.executeStep(AbstractOperationContext.java:673) [wildfly-controller-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.controller.AbstractOperationContext.doCompleteStep(AbstractOperationContext.java:484) [wildfly-controller-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.controller.AbstractOperationContext.completeStepInternal(AbstractOperationContext.java:281) [wildfly-controller-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.controller.AbstractOperationContext.executeOperation(AbstractOperationContext.java:276) [wildfly-controller-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.controller.ModelControllerImpl.internalExecute(ModelControllerImpl.java:271) [wildfly-controller-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.controller.ModelControllerImpl.execute(ModelControllerImpl.java:145) [wildfly-controller-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.controller.ModelControllerImpl$3$1$1.run(ModelControllerImpl.java:555) [wildfly-controller-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.controller.ModelControllerImpl$3$1$1.run(ModelControllerImpl.java:551) [wildfly-controller-8.1.0.Final.jar:8.1.0.Final]
at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.8.0_25]
at org.jboss.as.controller.ModelControllerImpl$3$1.run(ModelControllerImpl.java:551) [wildfly-controller-8.1.0.Final.jar:8.1.0.Final]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [rt.jar:1.8.0_25]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [rt.jar:1.8.0_25]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [rt.jar:1.8.0_25]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [rt.jar:1.8.0_25]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_25]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_25]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_25]
at org.jboss.threads.JBossThread.run(JBossThread.java:122) [jboss-threads-2.1.1.Final.jar:2.1.1.Final]
12:29:45,790 INFO [org.jboss.as.server] (DeploymentScanner-threads - 1) JBAS018565: Replaced deployment "Calendar-2dv012.war" with deployment "Calendar-2dv012.war"
12:29:45,790 INFO [org.jboss.as.controller] (DeploymentScanner-threads - 1) JBAS014774: Service status report
JBAS014777: Services which failed to start: service jboss.persistenceunit."Calendar-2dv012.war#Calendar-2dv012": org.jboss.msc.service.StartException in service jboss.persistenceunit."Calendar-2dv012.war#Calendar-2dv012": javax.persistence.PersistenceException: [PersistenceUnit: Calendar-2dv012] Unable to build Hibernate SessionFactory
日历类:
@Stateless
@LocalBean
public class CalendarEJB {
@PersistenceContext (name = "CalendarEJB")
EntityManager em;
public List<Calendar> listAllCalendars(){
TypedQuery<Calendar> theQuery = em.createQuery("SELECT c FROM Calendar c", Calendar.class);
List<Calendar> result = theQuery.getResultList();
return result;
}
public Calendar getCalendarById(int id){
TypedQuery<Calendar> theQuery = em.createQuery("SELECT c FROM Calendar c", Calendar.class);
List<Calendar> result = theQuery.getResultList();
for(int i=0;i<=result.size()-1;i++){
if(result.get(i).getCalendarId()== id){
return result.get(i);
}
}
return null;
}
DayEjb:
@Stateless
@LocalBean
public class DayEJB {
@PersistenceContext (name = "DayEJB")
EntityManager em;
public List<Day> listAllDays(){
TypedQuery<Day> theQuery = em.createQuery("SELECT d FROM Day d", Day.class);
List<Day> result = theQuery.getResultList();
return result;
}
public Day getDayById(int id){
TypedQuery<Day> theQuery = em.createQuery("SELECT d FROM Day d", Day.class);
List<Day> result = theQuery.getResultList();
for(int i=0;i<=result.size()-1;i++){
if(result.get(i).getIddays()== id){
return result.get(i);
}
}
return null;
}
public void createDay(Day d){
em.persist(d);
System.out.println("Data Added Successfully");
}
这是 Html:
<h:form>
<h3>Days:</h3>
<h:dataTable value="#{dayBean.allDays()}" var="day">
<h:column>
<f:facet name="header">ID</f:facet>
#{day.iddays}
</h:column>
<h:column>
<f:facet name="header">Date</f:facet>
#{day.date}
</h:column>
<h:column>
<f:facet name="header">Text</f:facet>
#{day.text}
</h:column>
<h:column>
<f:facet name="header">Link</f:facet>
#{day.link}
</h:column>
<h:column>
<f:facet name="header">Calendar ID</f:facet>
#{day.calendars_calendar_id}
</h:column>
</h:dataTable>
</h:form>
最佳答案
您的实体模型与数据库架构不匹配。
实体模型定义了一个关联Day -> Calendar
,如下所示:
@Entity
@Table(name = "days")
public class Day implements Serializable {
@ManyToOne
@JoinColumn(name="calendar_id")
private Calendar calendar;
}
但在数据库中,外键列称为calendars_calendar_id
,而不是calendar_id
。
关于java - com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException : Unknown column 'day0_.calendar_id' in 'field list' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27797806/
这是我的代码 14 20 {"Confirm Email"} 21 在第 17 行我得到错误 Type '{ pathname: string; user: { em
这是我的代码 14 20 {"Confirm Email"} 21 在第 17 行我得到错误 Type '{ pathname: string; user: { em
这个问题已经有答案了: How do I compare strings in Java? (23 个回答) 已关闭 8 年前。 为什么 KeyEvent.getKeyText(0).substrin
我正在尝试 Rust 的新 wasm32-unknown-unknown 目标,我在调用数学函数(例如 sin、cos、exp、atan2)时遇到问题。 cargo .toml: [package]
当我为 spring-boot 创建启动项目时,我在 pom 文件中收到此错误。这只是为了创建一个基本的 Spring Boot 项目 Project build error: Invalid pac
我已经订阅了我想要传输的数据。但不知何故它不起作用。我收到此错误: The property pipe is not available for type "OperatorFunction" 这是我
运行以下查询时。select * from surgerys where to_char(dt_surgery ,'DD-MM-YYYY' ) = to_char('12-02-2012','DD-M
我在运行存储过程时遇到以下异常: com.microsoft.sqlserver.jdbc.SQLServerException:不支持从 UNKNOWN 到 UNKNOWN 的转换。 过程定义如下:
我尝试运行以下代码。顺便说一句,我对 python 和 sklearn 都是新手。 import pandas as pd import numpy as np from sklearn.linear
我已经阅读了关于未知类型的官方文档,但我很难真正理解它是如何工作的。 人们可以在文档中读到:“在没有首先断言或缩小到更具体的类型之前,不允许对未知进行任何操作。” 但如果我有这个功能: const f
我正在尝试在Mac OS中设置Hadoop 2.6.0 我正在关注这篇文章: http://hadoop.apache.org/docs/r2.4.0/hadoop-project-dist/hado
配置 Nexus docker 注册表和代理“dockerhub-proxy”后,如下所述: https://help.sonatype.com/repomanager3/formats/docker
我收到此错误 - “ValueError:未知标签类型:'unknown'” 我已经在网上搜索但无法摆脱这个错误,顺便说一句,我是 python 的新手:) 我的数据有 5 行 22 列,最后一列是标
使用 SHA256 摘要标识符 拉取图像失败 最佳答案 不幸的是,这是 DockerHub 删除 Docker 1.9 守护进程的向后兼容性的副作用。当使用 Docker 1.10 推送图像时,较旧的
我是 postgresql 的新手,正在尝试使用全文搜索 to_tsvector但是我遇到了错误。 SQL 和错误 SELECT to_tsvector('english', 'The quick b
每当我这样做时 npm run watch ,第一次编译工作正常 - 但经过几次编译后,我最终会得到这个错误: 95% emitting unnamed compat pluginError: UNK
在一个新的 Angular 应用程序中,我收到以下错误:Error from chokidar : Error: UNKNOWN: unknown error, watch我已经删除并重新安装 nod
使用 Typescipt 4.x.x 我写了一些代码来实现其他语言 Elm/Rust/Haskell 中常用的 Maybe/Option 类型。 我想写一个可以接受映射类型的通用函数 type MyM
const submitted = useSelector((state) => state.post.submitted) 对于上面的状态。我得到错误: (参数)状态:未知对象的类型为“未知”。 这
我正在尝试将多架构 docker 镜像推送到 docker hub 并遇到错误(在 https://github.com/docker/distribution/issues/3100 处打开了 do
我是一名优秀的程序员,十分优秀!