최대 절전 모드 응용 프로그램에서 개체에 액세스하는 데 문제가 있습니다.최대 절전 모드 - 개체 속성에 액세스 할 수 없습니다.
클래스 푸 :
public class Foo {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private long id;
private String name;
Foo() {}
//getters, setters...
}
foo.hbm.xml
<class name="Foo" table="FOO">
<id name="id" type="long" column="ID" length="20">
<generator class="assigned" />
</id>
<property name="name" column="NAME" type="string"
length="50">
</property>
</class>
클래스 바 :
public class Bar{
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private long id;
private Date date;
private Foo foo;
private long quantity;
Bar() {}
//getters, setters...
}
bar.hbm.xml
<class name="Bar" table="BAR">
<id name="id" type="long" column="ID" length="20">
<generator class="assigned" />
</id>
<many-to-one name="foo" column="foo" class="Foo"
not-null="true"></many-to-one>
<property name="date" column="DATE" type="date">
</property>
<property name="quantity" column="QUANTITY" type="long"
length="20">
</property>
</class>
MyTableModel이있는 테이블을 AbstractTableModel로 확장했습니다. getValueAt라는 메서드가 있습니다.
public Object getValueAt(int rowIndex, int columnIndex) {
Bar b = ConsumptionList.get(rowIndex);
Object[] values = new Object[] { b.getId(), b.getDate(),
b.getFoo().getName(), _s.getQuantity() };
return values[columnIndex];
}
이 방법은 내가 b.getFoo(). getId()를 호출 할 때,하지만, 매우 잘 작동한다. . 난 b.getFoo() 대한 getName 호출하려고 할 때 ()은 다음 I는 다음과 같은 오류가 발생 : 그것은 Object[] values
맞춰 occours
Exception in thread "AWT-EventQueue-0" org.hibernate.LazyInitializationException: could not initialize proxy - no Session
at
org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:165)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:286)
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:185)
at Foo_$$_jvstdd_0.getName(Foo_$$_jvstdd_0.java)
at MyModel$MyTableModel.getValueAt(MyModel.java:66)
at javax.swing.JTable.getValueAt(Unknown Source)
at javax.swing.JTable.prepareRenderer(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paintCells(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paint(Unknown Source)
at javax.swing.plaf.ComponentUI.update(Unknown Source)
at javax.swing.JComponent.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JViewport.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager$4.run(Unknown Source)
at javax.swing.RepaintManager$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.access$1200(Unknown Source)
at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
. 이 객체에 대한 액세스 권한은 무엇입니까? (이 기능이 필요할 때 응용 프로그램에 여러 상황이 있기 때문에 세 번째 테이블을 만들고 싶지 않습니다.) 도움을 청합니다.
좋아, 그럼'b.getFoo(). getName()'을'b.getFoo(). getId()'로 바꿀 때 내 코드가 작동하는 이유는 무엇입니까? 제 생각에'Bar' 클래스가 생성되면,이 테이블의'Foo' id에만 넣습니다. 이름은 다른 테이블에 있습니다. 그래서'Bar'가 생성 될 때 Foo 속성을 채우고 싶습니다. 좋은 예, 덧붙여서 : –
나는 이것을 체크하고 불행히도, 나는이 에러보다 훨씬 더 많은'session.close(); '를 가지고있다. –
찾았습니다! MyTableModel 생성자에서'commit'을했습니다. 나는 이것에 대해 주석을 달았다.그래서 문제는'getValueAt()'메소드로 무엇을해야 하는가? 이 방법으로 매회 트랜잭션을 시작하고 커밋 하시겠습니까? 아니면 생성자에서 뭔가를할까요? 어떤 방법이 최선일까요? –