- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试从数据库中获取数据。 insert()
方法正在调用 fetch()
。
在 insert()
插入数据库后我得到 billNo
(Long) data.get("billNo")
得到账单号。
在 System.out.println("no is "+(Long) data.get("billNo"));
我正在打印显示正确值的值。
public void insert(){
Map data = dao.insertBill(bd);
String ss = (String) data.get("status");
if (ss.equalsIgnoreCase("success")) {
List<Object[]> aa = new ArrayList<Object[]>();
System.out.println("no is " + (Long) data.get("billNo"));//op 56
aa = dao.fetch((Long) data.get("billNo"), lc.getClient().getId());
System.out.println(" aa length is " + aa.size());//0
Object[] bdAndSum = aa.get(0);//line 122 java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
.....
}
}
获取方法
public List<Object[]> fetch(Long id, long cid) {
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction tx = session.beginTransaction();
List<Object[]> obj = null;
System.out.println("id " + id + " cid " + cid);
try {
String hql = "select distinct bd,sum(bpds.amount) from BillDetails as bd "
+ "left join fetch bd.customerDetails as cd "
+ "left join fetch bd.billProductSet as bpd "
+ "left join fetch bpd.product as pd "
+ "left join fetch bd.billPaidDetails as bpds "
+ "where bd.billNo=:id "
+ "and bd.client.id=:cid "
+ "group by bpd.id";
Query query = session.createQuery(hql);
query.setParameter("id", id);
query.setParameter("cid", cid);
System.out.println("id " + id + " cid " + cid);//id 56 cid 1
obj = query.list();
System.out.println("id " + id + " cid " + cid);//id 56 cid 1
System.out.println("Printing size of obj ");
System.out.println(" " + obj.size());//0
} catch (HibernateException e) {
if (tx != null) {
e.printStackTrace();
}
} finally {
session.close();
}
return obj;
}
我的问题是 dao.fetch((Long) data.get("billNo"), lc.getClient().getId());
没有从数据库中获取数据并且并给予异常(exception)
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
java.util.ArrayList.rangeCheck(ArrayList.java:638)
java.util.ArrayList.get(ArrayList.java:414)
iland.bill.BillNewAction.insert(BillNewAction.java:122)
但是如果我调用 dao.fetch(56, lc.getClient().getId());
正在从数据库中获取数据。
如何解决这个问题。
编辑:服务器控制台数据
no is 82
id 82 cid 1
id 82 cid 1
Hibernate:
/* select
distinct bd,
sum(bpds.amount)
from
BillDetails as bd
left join
fetch bd.customerDetails as cd
left join
fetch bd.billProductSet as bpd
left join
fetch bpd.product as pd
left join
fetch bd.billPaidDetails as bpds
where
bd.billNo=:id
and bd.client.id=:cid
group by
bpd.id */ select
distinct billdetail0_.bill_no as col_0_0_,
sum(billpaidde4_.amount) as col_1_0_,
customerde1_.id as id10_1_,
billproduc2_.product_id as product1_15_2_,
billproduc2_.bill_no as bill2_15_2_,
product3_.id as id4_3_,
billpaidde4_.id as id8_4_,
billdetail0_.bill_no as bill1_0_0_,
customerde1_.id as id10_1_,
billproduc2_.product_id as product1_15_2_,
billproduc2_.bill_no as bill2_15_2_,
product3_.id as id4_3_,
billpaidde4_.id as id8_4_,
billdetail0_.customer_id as customer2_0_0_,
billdetail0_.cid as cid0_0_,
billdetail0_.sub_total as sub4_0_0_,
billdetail0_.vat as vat0_0_,
billdetail0_.total as total0_0_,
billdetail0_.invoice_no as invoice7_0_0_,
billdetail0_.invoice_dt as invoice8_0_0_,
billdetail0_.status as status0_0_,
billdetail0_.description as descrip10_0_0_,
billdetail0_.add_date as add11_0_0_,
customerde1_.cid as cid10_1_,
customerde1_.name as name10_1_,
customerde1_.address as address10_1_,
customerde1_.city as city10_1_,
customerde1_.state as state10_1_,
customerde1_.country as country10_1_,
customerde1_.mobno as mobno10_1_,
customerde1_.type as type10_1_,
customerde1_.dob as dob10_1_,
customerde1_.anniversery as anniver11_10_1_,
customerde1_.age_range as age12_10_1_,
customerde1_.add_date as add13_10_1_,
customerde1_.status as status10_1_,
billproduc2_.cid as cid15_2_,
billproduc2_.qty as qty15_2_,
billproduc2_.unit_price as unit5_15_2_,
billproduc2_.selling_price as selling6_15_2_,
billproduc2_.discount_percent as discount7_15_2_,
billproduc2_.description as descript8_15_2_,
billproduc2_.bill_no as bill2_0_0__,
billproduc2_.product_id as product1_0__,
billproduc2_.bill_no as bill2_0__,
product3_.cid as cid4_3_,
product3_.barcode as barcode4_3_,
product3_.name as name4_3_,
product3_.description as descript5_4_3_,
product3_.quntity as quntity4_3_,
product3_.unit_price as unit7_4_3_,
product3_.selling_price as selling8_4_3_,
product3_.discount_percent as discount9_4_3_,
product3_.add_date as add10_4_3_,
product3_.status as status4_3_,
billpaidde4_.cid as cid8_4_,
billpaidde4_.bill_no as bill3_8_4_,
billpaidde4_.amount as amount8_4_,
billpaidde4_.payment_mode as payment5_8_4_,
billpaidde4_.dt as dt8_4_,
billpaidde4_.adddate as adddate8_4_,
billpaidde4_.bill_no as bill3_0_1__,
billpaidde4_.id as id1__
from
xrcwrn_retail_shop.bill_details billdetail0_
left outer join
xrcwrn_retail_shop.customer_details customerde1_
on billdetail0_.customer_id=customerde1_.id
left outer join
xrcwrn_retail_shop.bill_product billproduc2_
on billdetail0_.bill_no=billproduc2_.bill_no
left outer join
xrcwrn_retail_shop.product product3_
on billproduc2_.product_id=product3_.id
left outer join
xrcwrn_retail_shop.bill_paid_details billpaidde4_
on billdetail0_.bill_no=billpaidde4_.bill_no
where
billdetail0_.bill_no=?
and billdetail0_.cid=?
group by
billproduc2_.product_id,
Sep 21, 2014 3:09:28 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger error
SEVERE: Exception occurred during processing request: Index: 0, Size: 0
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:638)
at java.util.ArrayList.get(ArrayList.java:414)
at iland.bill.BillNewAction.insert(BillNewAction.java:122)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:450)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:289)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:252)
at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:167)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:239)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:239)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:252)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
billproduc2_.bill_no
id 82 cid 1
Printing size of obj
0
aa length is 0
at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:161)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:189)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:563)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:744)
账单明细 POJO
public class BillDetails implements java.io.Serializable {
private Long billNo;
private Client client;
//getter and setter
}
public class Client implements java.io.Serializable {
private Long id;
//getter and setter
}
编辑: 我正在使用 sql 插入记录并从此处返回最新插入的 ID,这没问题。 我发现 hibernate 无法使用插入的 ID 获取最新记录。
我在使用上述相同条件的多个地方都面临同样的问题。
我的数据库插入代码是:http://pastebin.com/LfP6Hfwc
最佳答案
我认为HibernateTransactionManager
是你的解决方案
This transaction manager is appropriate for applications that use a single Hibernate SessionFactory for transactional data access, but it also supports direct DataSource access within a transaction (i.e. plain JDBC code working with the same DataSource).
基本上,在某些时候,您必须使用 setDataSource(DataSource dataSource)
注册您的数据源。
Set the JDBC DataSource that this instance should manage transactions for. The DataSource should match the one used by the Hibernate SessionFactory: for example, you could specify the same JNDI DataSource for both.
DataSource source = ...;
hibernateTransactionManager.setDataSource(dataSource);
// [...]
Connection con = source.getConnection();
// Do your inserts and stuff
然后,使用hibernateTransactionManager
获取您的对象
public List<Object[]> fetch(Long id, long cid)
{
Session session = hibernateTransactionManager.getSessionFactory().openSession();
Transaction tx = session.beginTransaction();
// [...]
关于java - Hibernate 没有从数据库中获取最新插入的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25931634/
我需要将文本放在 中在一个 Div 中,在另一个 Div 中,在另一个 Div 中。所以这是它的样子: #document Change PIN
奇怪的事情发生了。 我有一个基本的 html 代码。 html,头部, body 。(因为我收到了一些反对票,这里是完整的代码) 这是我的CSS: html { backgroun
我正在尝试将 Assets 中的一组图像加载到 UICollectionview 中存在的 ImageView 中,但每当我运行应用程序时它都会显示错误。而且也没有显示图像。 我在ViewDidLoa
我需要根据带参数的 perl 脚本的输出更改一些环境变量。在 tcsh 中,我可以使用别名命令来评估 perl 脚本的输出。 tcsh: alias setsdk 'eval `/localhome/
我使用 Windows 身份验证创建了一个新的 Blazor(服务器端)应用程序,并使用 IIS Express 运行它。它将显示一条消息“Hello Domain\User!”来自右上方的以下 Ra
这是我的方法 void login(Event event);我想知道 Kotlin 中应该如何 最佳答案 在 Kotlin 中通配符运算符是 * 。它指示编译器它是未知的,但一旦知道,就不会有其他类
看下面的代码 for story in book if story.title.length < 140 - var story
我正在尝试用 C 语言学习字符串处理。我写了一个程序,它存储了一些音乐轨道,并帮助用户检查他/她想到的歌曲是否存在于存储的轨道中。这是通过要求用户输入一串字符来完成的。然后程序使用 strstr()
我正在学习 sscanf 并遇到如下格式字符串: sscanf("%[^:]:%[^*=]%*[*=]%n",a,b,&c); 我理解 %[^:] 部分意味着扫描直到遇到 ':' 并将其分配给 a。:
def char_check(x,y): if (str(x) in y or x.find(y) > -1) or (str(y) in x or y.find(x) > -1):
我有一种情况,我想将文本文件中的现有行包含到一个新 block 中。 line 1 line 2 line in block line 3 line 4 应该变成 line 1 line 2 line
我有一个新项目,我正在尝试设置 Django 调试工具栏。首先,我尝试了快速设置,它只涉及将 'debug_toolbar' 添加到我的已安装应用程序列表中。有了这个,当我转到我的根 URL 时,调试
在 Matlab 中,如果我有一个函数 f,例如签名是 f(a,b,c),我可以创建一个只有一个变量 b 的函数,它将使用固定的 a=a1 和 c=c1 调用 f: g = @(b) f(a1, b,
我不明白为什么 ForEach 中的元素之间有多余的垂直间距在 VStack 里面在 ScrollView 里面使用 GeometryReader 时渲染自定义水平分隔线。 Scrol
我想知道,是否有关于何时使用 session 和 cookie 的指南或最佳实践? 什么应该和什么不应该存储在其中?谢谢! 最佳答案 这些文档很好地了解了 session cookie 的安全问题以及
我在 scipy/numpy 中有一个 Nx3 矩阵,我想用它制作一个 3 维条形图,其中 X 轴和 Y 轴由矩阵的第一列和第二列的值、高度确定每个条形的 是矩阵中的第三列,条形的数量由 N 确定。
假设我用两种不同的方式初始化信号量 sem_init(&randomsem,0,1) sem_init(&randomsem,0,0) 现在, sem_wait(&randomsem) 在这两种情况下
我怀疑该值如何存储在“WORD”中,因为 PStr 包含实际输出。? 既然Pstr中存储的是小写到大写的字母,那么在printf中如何将其给出为“WORD”。有人可以吗?解释一下? #include
我有一个 3x3 数组: var my_array = [[0,1,2], [3,4,5], [6,7,8]]; 并想获得它的第一个 2
我意识到您可以使用如下方式轻松检查焦点: var hasFocus = true; $(window).blur(function(){ hasFocus = false; }); $(win
我是一名优秀的程序员,十分优秀!