[jboss-user] [EJB 3.0] - illegal access to loading collection
mwalbrun
do-not-reply at jboss.com
Mon Jan 14 12:31:16 EST 2008
Hi all,
i have the following problem. I have an EJB 3.0 successfully running on windows. now i copied the project onto my mac with mac os x leopard and when i start it get the following exception
18:17:31,669 ERROR [LazyInitializationException] illegal access to loading collection
| org.hibernate.LazyInitializationException: illegal access to loading collection
| at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:341)
| at org.hibernate.collection.PersistentSet.add(PersistentSet.java:189)
| at de.optitool.domain.sys.Schedule.addEntry(Schedule.java:234)
| at de.optitool.domain.sys.ScheduleEntry.setSchedule(ScheduleEntry.java:316)
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:42)
| at org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:337)
| at org.hibernate.tuple.entity.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:200)
| at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3566)
| at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:129)
| at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:854)
| at org.hibernate.loader.Loader.doQuery(Loader.java:729)
| at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
| at org.hibernate.loader.Loader.doList(Loader.java:2220)
| at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
| at org.hibernate.loader.Loader.list(Loader.java:2099)
| at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
| at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
| at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
| at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
| at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
| at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:64)
| at de.optitool.session.biz.tp.OrderSessionBean.test(OrderSessionBean.java:76)
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
| at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
| at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor.invoke(ExtendedPersistenceContextPropagationInterceptor.java:57)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
| at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:83)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
| at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.stateful.StatefulContainer.dynamicInvoke(StatefulContainer.java:335)
| at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106)
| at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
| at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:769)
| at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:573)
| at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:373)
| at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:166)
| 18:17:44,151 ERROR [STDERR] javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: Exception occurred inside setter of de.optitool.domain.sys.ScheduleEntry.schedule
| 18:17:44,153 ERROR [STDERR] at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:629)
| 18:17:44,155 ERROR [STDERR] at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:73)
| 18:17:44,156 ERROR [STDERR] at de.optitool.session.biz.tp.OrderSessionBean.test(OrderSessionBean.java:76)
| 18:17:44,157 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| 18:17:44,158 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
| 18:17:44,159 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| 18:17:44,159 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
| 18:17:44,160 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
| 18:17:44,161 ERROR [STDERR] at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
| 18:17:44,162 ERROR [STDERR] at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
| 18:17:44,163 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| 18:17:44,164 ERROR [STDERR] at org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor.invoke(ExtendedPersistenceContextPropagationInterceptor.java:57)
| 18:17:44,165 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| 18:17:44,166 ERROR [STDERR] at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
| 18:17:44,166 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| 18:17:44,167 ERROR [STDERR] at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
| 18:17:44,168 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| 18:17:44,169 ERROR [STDERR] at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
| 18:17:44,169 ERROR [STDERR] at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
| 18:17:44,170 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| 18:17:44,171 ERROR [STDERR] at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
| 18:17:44,171 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| 18:17:44,172 ERROR [STDERR] at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:83)
| 18:17:44,173 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| 18:17:44,174 ERROR [STDERR] at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
| 18:17:44,175 ERROR [STDERR] at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
| 18:17:44,175 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| 18:17:44,176 ERROR [STDERR] at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
| 18:17:44,177 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| 18:17:44,178 ERROR [STDERR] at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
| 18:17:44,178 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| 18:17:44,179 ERROR [STDERR] at org.jboss.ejb3.stateful.StatefulContainer.dynamicInvoke(StatefulContainer.java:335)
| 18:17:44,180 ERROR [STDERR] at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106)
| 18:17:44,180 ERROR [STDERR] at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
| 18:17:44,181 ERROR [STDERR] at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:769)
| 18:17:44,182 ERROR [STDERR] at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:573)
| 18:17:44,183 ERROR [STDERR] at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:373)
| 18:17:44,183 ERROR [STDERR] at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:166)
| 18:17:44,184 ERROR [STDERR] Caused by: org.hibernate.PropertyAccessException: Exception occurred inside setter of de.optitool.domain.sys.ScheduleEntry.schedule
| 18:17:44,185 ERROR [STDERR] at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:65)
| 18:17:44,186 ERROR [STDERR] at org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:337)
| 18:17:44,187 ERROR [STDERR] at org.hibernate.tuple.entity.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:200)
| 18:17:44,188 ERROR [STDERR] at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3566)
| 18:17:44,188 ERROR [STDERR] at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:129)
| 18:17:44,189 ERROR [STDERR] at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:854)
| 18:17:44,190 ERROR [STDERR] at org.hibernate.loader.Loader.doQuery(Loader.java:729)
| 18:17:44,190 ERROR [STDERR] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
| 18:17:44,191 ERROR [STDERR] at org.hibernate.loader.Loader.doList(Loader.java:2220)
| 18:17:44,192 ERROR [STDERR] at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
| 18:17:44,192 ERROR [STDERR] at org.hibernate.loader.Loader.list(Loader.java:2099)
| 18:17:44,193 ERROR [STDERR] at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
| 18:17:44,194 ERROR [STDERR] at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
| 18:17:44,194 ERROR [STDERR] at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
| 18:17:44,195 ERROR [STDERR] at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
| 18:17:44,196 ERROR [STDERR] at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
| 18:17:44,196 ERROR [STDERR] at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:64)
| 18:17:44,197 ERROR [STDERR] ... 36 more
| 18:17:44,198 ERROR [STDERR] Caused by: java.lang.reflect.InvocationTargetException
| 18:17:44,198 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| 18:17:44,199 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
| 18:17:44,200 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| 18:17:44,200 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
| 18:17:44,201 ERROR [STDERR] at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:42)
| 18:17:44,202 ERROR [STDERR] ... 52 more
| 18:17:44,202 ERROR [STDERR] Caused by: org.hibernate.LazyInitializationException: illegal access to loading collection
| 18:17:44,203 ERROR [STDERR] at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:341)
| 18:17:44,204 ERROR [STDERR] at org.hibernate.collection.PersistentSet.add(PersistentSet.java:189)
| 18:17:44,204 ERROR [STDERR] at de.optitool.domain.sys.Schedule.addEntry(Schedule.java:234)
| 18:17:44,205 ERROR [STDERR] at de.optitool.domain.sys.ScheduleEntry.setSchedule(ScheduleEntry.java:316)
| 18:17:44,206 ERROR [STDERR] ... 57 more
My two Entities are as follows...
package de.optitool.domain.sys;
|
| import java.util.ArrayList;
| import java.util.Calendar;
| import java.util.Collection;
| import java.util.Collections;
| import java.util.Comparator;
| import java.util.Date;
| import java.util.HashSet;
| import java.util.Iterator;
| import java.util.List;
| import java.util.Set;
|
| import javax.persistence.CascadeType;
| import javax.persistence.Column;
| import javax.persistence.Entity;
| import javax.persistence.FetchType;
| import javax.persistence.GeneratedValue;
| import javax.persistence.GenerationType;
| import javax.persistence.Id;
| import javax.persistence.OneToMany;
| import javax.persistence.Table;
| import javax.persistence.TableGenerator;
| import javax.persistence.Transient;
| import javax.persistence.Version;
|
| import de.optitool.common.exception.VetoException;
| import de.optitool.common.sys.ISchedule;
| import de.optitool.common.sys.IScheduleEntry;
| import de.optitool.common.sys.ScheduleEntryEndComparator;
| import de.optitool.common.sys.ScheduleEntryStartComparator;
|
| @Entity
| @Table(name="schedule")
| public class Schedule implements java.io.Serializable, ISchedule {
|
|
| private static final long serialVersionUID = 6197633623641866232L;
| private int scheduleId;
| private short jdoVersion;
| private Set<ScheduleEntry> scheduleEntries = new HashSet<ScheduleEntry>();
|
| public Schedule() {
| }
|
| public Schedule(Set<ScheduleEntry> scheduleEntries) {
| this.scheduleEntries = scheduleEntries;
| }
|
| @TableGenerator(name="schedule",
| table="jdo_keygen",
| pkColumnName="table_name",
| valueColumnName="last_used_id",
| pkColumnValue="schedule",
| allocationSize=10)
| @Id
| @GeneratedValue(strategy=GenerationType.TABLE, generator="schedule")
| @Column(name="schedule_id", unique=true, nullable=false)
| public int getScheduleId() {
| return this.scheduleId;
| }
|
| protected void setScheduleId(int scheduleId) {
| this.scheduleId = scheduleId;
| }
|
| @Version
| @Column(name="jdo_version", nullable=false)
| protected short getJdoVersion() {
| return this.jdoVersion;
| }
|
| protected void setJdoVersion(short jdoVersion) {
| this.jdoVersion = jdoVersion;
| }
|
| /**
| * @see net.uniopt.sys.ISchedule#getEntries()
| */
| @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="schedule")
| public Set<ScheduleEntry> getScheduleEntries() {
| return this.scheduleEntries;
| }
|
| public void setScheduleEntries(Set<ScheduleEntry> scheduleEntries) {
| this.scheduleEntries = scheduleEntries;
| }
|
|
| //Methods I do not know why they are in here
|
| /**
| * @param entry
| */
| public void entryChanged (IScheduleEntry entry) {
| // We do nothing here, at the moment.
| // setStartEndTime();
| }
|
| /**
| * @return First second that's contained by this schedule.
| */
| @Transient
| private Date calcStartTime() {
| // Get the list of entries sorted ascending by their begin
| List<IScheduleEntry> list = getEntries (new ScheduleEntryStartComparator());
| if (list == null || list.isEmpty()) return null;
|
| // Take the first one from the list
| IScheduleEntry item = (IScheduleEntry)list.get (0);
| Date d = item.getStartDate();
| if (d == null) return null;
|
| Calendar cres = Calendar.getInstance();
|
| // Set the date part first
| Calendar dc = Calendar.getInstance();
| dc.setTime (d);
| cres.set (Calendar.YEAR, dc.get (Calendar.YEAR));
| cres.set (Calendar.MONTH, dc.get (Calendar.MONTH));
| cres.set (Calendar.DATE, dc.get (Calendar.DATE));
|
| // Ignore milliseconds
| cres.set (Calendar.MILLISECOND, 0);
|
| // Set the time part, if startTime of the entry is null we set it to 00:00:00
| d = item.getStartTime();
| if (d == null) {
| cres.set (Calendar.MINUTE, 0);
| cres.set (Calendar.SECOND, 0);
| cres.set (Calendar.HOUR_OF_DAY, 0);
| } else {
| Calendar tc = Calendar.getInstance();
| tc.setTime (d);
| cres.set (Calendar.HOUR_OF_DAY, tc.get (Calendar.HOUR_OF_DAY));
| cres.set (Calendar.MINUTE, tc.get (Calendar.MINUTE));
| cres.set (Calendar.SECOND, tc.get (Calendar.SECOND));
| }
| return cres.getTime();
| }
|
| /**
| * @return Last second that's contained by this schedule
| */
| @Transient
| private Date calcEndTime() {
| // Get the list of entries sorted ascending by their end date
| List<IScheduleEntry> list = getEntries (new ScheduleEntryEndComparator());
| if (list == null || list.isEmpty()) return null;
|
| // Take the last one from the list
| IScheduleEntry item = (IScheduleEntry)list.get (list.size()-1);
| Date d = item.getEndDate();
| if (d == null) return null;
|
| Calendar cres = Calendar.getInstance();
|
| // Set the date part
| Calendar dc = Calendar.getInstance();
| dc.setTime (d);
| cres.set (Calendar.YEAR, dc.get (Calendar.YEAR));
| cres.set (Calendar.MONTH, dc.get (Calendar.MONTH));
| cres.set (Calendar.DATE, dc.get (Calendar.DATE));
|
| // Ignore milliseconds
| cres.set (Calendar.MILLISECOND, 0);
|
| // Set the time part, if endTime of entry is null we set it to 24:00:00
| d = item.getEndTime();
| if (d != null) {
| Calendar tc = Calendar.getInstance();
| tc.setTime (d);
| cres.set (Calendar.HOUR_OF_DAY, tc.get (Calendar.HOUR_OF_DAY));
| cres.set (Calendar.MINUTE, tc.get (Calendar.MINUTE));
| cres.set (Calendar.SECOND, tc.get (Calendar.SECOND));
| } else {
| cres.set (Calendar.MINUTE, 0);
| cres.set (Calendar.SECOND, 0);
| cres.set (Calendar.HOUR_OF_DAY, 24);
| }
| return cres.getTime();
| }
|
| /**
| * Create a Date object from the given date anyDate and
| * initialize the time part with the given seconds of day.
| * @param anyDate - date used to initialize the date part (y,m,d)
| * @param second - second of the day, used to initialize the time part (h,m,s)
| * @return - the date object just created
| */
| @Transient
| private Date generateTime (Date anyDate, int second) {
| if (anyDate == null) anyDate = new Date(); // if no date given we take today.
| Calendar calendar = Calendar.getInstance();
| calendar.setTime (anyDate);
| calendar.set (Calendar.HOUR_OF_DAY, second/3600);
| second %= 3600;
| calendar.set (Calendar.MINUTE, second/60);
| second %= 60;
| calendar.set (Calendar.SECOND, second);
| return calendar.getTime();
| }
|
| /**
| * @param entry
| * @return
| */
| @Transient
| protected boolean isCompatible (ScheduleEntry entry) {
| // TODO If this new entry completely overlaps another or another is completely overlapped
| // TODO by the new one false is to be returned!
| return true;
| }
| //Methods implemented by the Interface
|
| @Transient
| /**
| * @see net.uniopt.sys.ISchedule#getEntries()
| */
| public Set<IScheduleEntry> getEntries() {
| Set<IScheduleEntry> set = new HashSet<IScheduleEntry>();
| if (scheduleEntries != null && !scheduleEntries.isEmpty())
| set.addAll (scheduleEntries);
| return set;
| }
|
| /**
| * @see net.uniopt.sys.ISchedule#addEntry(net.uniopt.sys.IScheduleEntry)
| */
| @Transient
| public boolean addEntry (IScheduleEntry entry) {
| if (scheduleEntries == null)
| scheduleEntries = new HashSet<ScheduleEntry>(17);
| boolean added = entry instanceof ScheduleEntry ? scheduleEntries.add ((ScheduleEntry)entry) : false;
| if (added)
| entry.setSchedule (this);
| return added;
| }
|
| /**
| * Convinience method for {@link #createEntry(Date, int, Date, int, int)} with the note set to null
| * and the all days of the week selected.
| * @param startDate - Day the timeframe begins (time part is ignored).
| * @param startSecond - Second of the day the timeframe begins (every day).
| * @param endDate - Day the interval ends (time part is ignored).
| * @param endSecond - Second of the day the timeframe ends every day.
| * @param dowIndicator - a bitmap of day-of-the-week constants defined by the ISchedule interface.
| * @return The new entry or null if it cannot be created or is not compatible.
| * @throws VetoException
| *
| * @see net.uniopt.sys.ISchedule#createEntry(java.util.Date, int, java.util.Date, int)
| */
| @Transient
| public IScheduleEntry createEntry (Date startDate, int startSecond, Date endDate, int endSecond) throws VetoException {
| return createEntry (startDate, startSecond, endDate, endSecond, ISchedule.ALLDAYS, null);
| }
|
| /**
| * Convinience method for {@link #createEntry(Date, int, Date, int, int, String)} with the note set to null.
| * @param startDate - Day the timeframe begins (time part is ignored).
| * @param startSecond - Second of the day the timeframe begins (every day).
| * @param endDate - Day the interval ends (time part is ignored).
| * @param endSecond - Second of the day the timeframe ends every day.
| * @param dowIndicator - a bitmap of day-of-the-week constants defined by the ISchedule interface.
| * @return The new entry or null if it cannot be created or is not compatible.
| * @throws VetoException
| *
| * @see net.uniopt.sys.ISchedule#createEntry(java.util.Date, int, java.util.Date, int, int)
| */
| @Transient
| public IScheduleEntry createEntry (Date startDate, int startSecond, Date endDate, int endSecond, int dowIndicator) throws VetoException {
| return createEntry (startDate, startSecond, endDate, endSecond, dowIndicator, null);
| }
|
| /**
| * Create a new entry (timeframe) within this schedule.
| * If the new entry is not compatible with the existing ones null is returned.
| * (e.g., it completely overlaps an older one or is completely overlapped by an older one)
| * @param startDate - Day the timeframe begins (time part is ignored).
| * @param startSecond - Second of the day the timeframe begins (every day).
| * @param endDate - Day the interval ends (time part is ignored).
| * @param endSecond - Second of the day the timeframe ends every day.
| * @param dowIndicator - a bitmap of day-of-the-week constants defined by the ISchedule interface.
| * @param note - An arbitrary annotation.
| * @return The new entry or null if it cannot be created or is not compatible.
| * @throws VetoException
| *
| * @see net.uniopt.sys.ISchedule#createEntry(java.util.Date, int, java.util.Date, int, int, java.lang.String)
| */
| @Transient
| public IScheduleEntry createEntry (Date startDate, int startSecond, Date endDate, int endSecond, int dowIndicator, String note) throws VetoException {
| return createEntry (startDate,
| generateTime (startDate, startSecond),
| endDate,
| generateTime (endDate, endSecond),
| dowIndicator,
| note
| );
| }
|
| /**
| * @throws VetoException
| *
| * @see net.uniopt.sys.ISchedule#createEntry(java.util.Date, java.lang.Integer, java.util.Date, java.lang.Integer, int, java.lang.String)
| */
| @Transient
| public IScheduleEntry createEntry (Date startDate, Integer startSecond, Date endDate, Integer endSecond, int dowIndicator, String note) throws VetoException {
| int tStart = startSecond == null ? 0 : startSecond.intValue();
| int tEnd = endSecond == null ? 86400 : endSecond.intValue();
| ScheduleEntry entry = (ScheduleEntry)createEntry (startDate, tStart, endDate, tEnd, dowIndicator, note);
| return entry;
| }
|
| /**
| * Create a new entry (timeframe) within this schedule.
| * If the new entry is not compatible with the existing ones null is returned.
| * (e.g., it completely overlaps an older one or is completely overlapped by an older one)
| * @param startDate - Day the timeframe begins (time part is ignored).
| * @param startTime - Time of the day the timeframe begins (every day), i.e., the date-part is ignored
| * @param endDate - Day the interval ends (time part is ignored).
| * @param endTime - Time of the day the timeframe ends every day, i.e., the date-part is ignored
| * @param dow - a bitmap of day-of-the-week constants defined by the ISchedule interface.
| * @param note - An arbitrary annotation.
| * @return The new entry or null if it cannot be created or is not compatible.
| * @throws VetoException
| *
| * @see net.uniopt.sys.ISchedule#createEntry(java.util.Date, int, java.util.Date, int, int, java.lang.String)
| */
| @Transient
| public IScheduleEntry createEntry (Date startDate, Date startTime, Date endDate, Date endTime, int dow, String note) throws VetoException {
| ScheduleEntry entry = new ScheduleEntry();
| entry.setValues (startDate, startTime, endDate, endTime);
| entry.setDow (dow);
| entry.setNote (note);
| if (isCompatible (entry)) {
| entry.setSchedule (this);
| addEntry (entry);
| return entry;
| }
| return null;
| }
|
| /**
| * @see net.uniopt.sys.ISchedule#getEarliest()
| */
| @Transient
| public IScheduleEntry getEarliest () {
| List<IScheduleEntry> ents = new ArrayList<IScheduleEntry> (getEntries());
| if (ents.isEmpty()) return null;
| Collections.sort (ents, new ScheduleEntryStartComparator());
| return ents.get(0);
| }
|
| /**
| * @return The last moment managed by the schedule.
| *
| * @see net.uniopt.sys.ISchedule#getEndTime()
| */
| @Transient
| public Date getEndTime() {
| return calcEndTime();
| }
|
| /**
| * @see net.uniopt.sys.ISchedule#getEntries(java.util.Comparator)
| */
| @Transient
| public List<IScheduleEntry> getEntries (Comparator<IScheduleEntry> sortedBy) {
| Set<IScheduleEntry> c = getEntries();
| List<IScheduleEntry> sortedEntries = c == null ? new ArrayList<IScheduleEntry>() : new ArrayList<IScheduleEntry> (c);
| if (sortedBy!=null) Collections.sort (sortedEntries, sortedBy);
| return sortedEntries;
| }
|
| /**
| * Returns all schedule entries (timeframes), that contain the given point in time.
| * @param date - The date part of the point in time of interest
| * @param minute - The minute of the day of the moment of interest.
| * @return - All entries containing the given moment.
| *
| * @see net.uniopt.sys.ISchedule#getEntriesContaining(java.util.Date, int)
| */
| @Transient
| public List<IScheduleEntry> getEntriesContaining (Date date, int minute) {
| ArrayList<IScheduleEntry> list = new ArrayList<IScheduleEntry>();
| for (IScheduleEntry entry : getEntries()) {
| if (entry instanceof ScheduleEntry && ((ScheduleEntry)entry).contains (date, minute))
| list.add (entry);
| }
| return list;
| }
|
| /**
| * @see net.uniopt.sys.ISchedule#getLatest()
| */
| @Transient
| public IScheduleEntry getLatest() {
| List<IScheduleEntry> ents = new ArrayList<IScheduleEntry> (getEntries());
| if (ents.isEmpty()) return null;
| Collections.sort (ents, new ScheduleEntryEndComparator());
| return ents.get(0);
| }
|
| /**
| * @return The first moment that's part of the schedule.
| *
| * @see net.uniopt.sys.ISchedule#getStartTime()
| */
| @Transient
| public Date getStartTime() {
| return calcStartTime();
| }
|
| /**
| * @see net.uniopt.sys.ISchedule#isEmpty()
| */
| @Transient
| public boolean isEmpty() {
| return (scheduleEntries == null || scheduleEntries.isEmpty());
| }
|
| /**
| * @see net.uniopt.sys.ISchedule#removeAll()
| */
| @Transient
| public void removeAll() {
| Collection<IScheduleEntry> c = getEntries();
| if (c != null && !c.isEmpty()) {
| Iterator<?> it = c.iterator();
| while (it.hasNext()) removeEntry ((IScheduleEntry)it.next());
| }
| }
|
| /**
| * @see net.uniopt.sys.ISchedule#removeEntry(net.uniopt.sys.IScheduleEntry)
| */
| @Transient
| public boolean removeEntry (IScheduleEntry entry) {
| boolean removed = (scheduleEntries == null ? false : scheduleEntries.remove (entry));
| if (removed) entry.setSchedule (null);
| return removed;
| }
| }
package de.optitool.domain.sys;
|
| import java.util.Calendar;
| import java.util.Comparator;
| import java.util.Date;
|
| import javax.persistence.Column;
| import javax.persistence.Entity;
| import javax.persistence.FetchType;
| import javax.persistence.GeneratedValue;
| import javax.persistence.GenerationType;
| import javax.persistence.Id;
| import javax.persistence.JoinColumn;
| import javax.persistence.ManyToOne;
| import javax.persistence.Table;
| import javax.persistence.TableGenerator;
| import javax.persistence.Transient;
| import javax.persistence.Version;
|
| import de.optitool.common.exception.VetoException;
| import de.optitool.common.sys.ISchedule;
| import de.optitool.common.sys.IScheduleEntry;
| import de.optitool.common.util.TimeUtil;
|
| @Entity
| @Table(name="schedule_entry")
| public class ScheduleEntry implements java.io.Serializable, IScheduleEntry {
|
| private static final long serialVersionUID = 6000616020745378569L;
|
| private int scheduleEntryId;
| private Schedule schedule;
| private int down;
| private Date endDate;
| private Date endTime;
| private Date startDate;
| private Date startTime;
| private boolean up;
| private String note;
| private short jdoVersion;
|
| /** Days of the week this entry matters.*/
| private int dow=Schedule.WORKINGDAYS;
|
| public ScheduleEntry() {
| }
|
| public ScheduleEntry(Schedule schedule, int down, boolean up) {
| this.schedule = schedule;
| this.down = down;
| this.up = up;
| }
|
| public ScheduleEntry(Schedule schedule, int down, Date endDate, Date endTime, Date startDate,
| Date startTime, boolean up, String note) {
|
| this.schedule = schedule;
| this.down = down;
| this.endDate = endDate;
| this.endTime = endTime;
| this.startDate = startDate;
| this.startTime = startTime;
| this.up = up;
| this.note = note;
| }
|
| @TableGenerator(name="schedule_entry",
| table="jdo_keygen",
| pkColumnName="table_name",
| valueColumnName="last_used_id",
| pkColumnValue="schedule_entry",
| allocationSize=10)
| @Id
| @GeneratedValue(strategy=GenerationType.TABLE, generator="schedule_entry")
| @Column(name="schedule_entry_id", unique=true, nullable=false)
| public int getScheduleEntryId() {
| return this.scheduleEntryId;
| }
|
| protected void setScheduleEntryId(int scheduleEntryId) {
| this.scheduleEntryId = scheduleEntryId;
| }
|
| @ManyToOne(fetch=FetchType.LAZY)
| @JoinColumn(name="schedule_id", nullable=false)
| public Schedule getSchedule() {
| return this.schedule;
| }
|
| public void setSchedule(Schedule schedule) {
| this.schedule = schedule;
| }
|
| @Column(name="dow", nullable=false)
| public int getDown() {
| return this.down;
| }
|
| public void setDown(int down) {
| this.down = down;
| }
|
| @Column(name="end_date", length=19)
| public Date getEndDate() {
| return this.endDate;
| }
|
| public void setEndDate(Date endDate) {
| this.endDate = endDate;
| }
|
| @Column(name="end_time", length=19)
| public Date getEndTime() {
| return this.endTime;
| }
|
| public void setEndTime(Date endTime) {
| this.endTime = endTime;
| }
|
| @Column(name="start_date", length=19)
| public Date getStartDate() {
| return this.startDate;
| }
|
| public void setStartDate(Date startDate) {
| this.startDate = startDate;
| }
|
| @Column(name="start_time", length=19)
| public Date getStartTime() {
| return this.startTime;
| }
|
| public void setStartTime(Date startTime) {
| this.startTime = startTime;
| }
|
| @Column(name="u", nullable=false)
| public boolean isUp() {
| return this.up;
| }
|
| public void setUp(boolean up) {
| this.up = up;
| }
|
| @Column(name="note")
| public String getNote() {
| return this.note;
| }
|
| public void setNote(String note) {
| this.note = note;
| }
|
| @Version
| @Column(name="jdo_version", nullable=false)
| protected short getJdoVersion() {
| return this.jdoVersion;
| }
|
| protected void setJdoVersion(short jdoVersion) {
| this.jdoVersion = jdoVersion;
| }
|
| //Methods I do not know
| /**
| * Does this schedule entry (timeframe) contain the given point in time.
| * @param date - The date part (year,month,day) of the point in time.
| * @param minute - Minute of the day of the point in time.
| * @return Whether this timeframe contains the given point in time.
| */
| public boolean contains (Date date, int minute) {
| if (startDate != null && date.before (startDate)) return false;
| if (endDate != null && date.after (endDate)) return false;
| Calendar c = Calendar.getInstance();
| c.setTime (date);
| if ((TimeUtil.encode (c.get (Calendar.DAY_OF_WEEK)) & dow) == 0) return false;
|
| // If startTime is null it's assumed 0 a.m., so the given minute can't be before but still the same day
| if (startTime != null) {
| c.setTime (startTime);
| int min = c.get (Calendar.HOUR_OF_DAY) * 60 + c.get (Calendar.MINUTE);
| if (minute < min) return false;
| }
| // If endTime is null it's assumed midnight, so the given minute can't be after but still the same day
| if (endTime != null) {
| c.setTime (endTime);
| int min = c.get (Calendar.HOUR_OF_DAY) * 60 + c.get (Calendar.MINUTE);
| if (minute > min) return false;
| }
| return true;
| }
|
| /**
| * Checks two given date/time pairs if they would make a valid ScheduleEntry.
| * <br>
| * The following criteria is checked:
| * <ul>
| * <li> if both date parts are given, the startDate/startTime must be before endDate/endTime </li>
| * <li> if no date parts are given, startTime must be before endTime </li>
| * <li> if only one date part is given, there is no further restriction on time parts.
| * </ul>
| */
| protected boolean isValidScheduleEntry (Date startDate, Date startTime, Date endDate, Date endTime) {
| Date startDateTime = TimeUtil.combine (startDate, startTime);
| Date endDateTime = TimeUtil.combine (endDate, endTime);
|
| if ((startDateTime != null) && (endDateTime != null)) {
| // both Date parts given, startDateTime must be before endDateTime
| return (startDateTime.compareTo (endDateTime) <= 0);
| } else if ((startDate == null) && (endDate == null)) {
| if ((startTime != null) && (endTime != null)) {
| // no Date parts given, startTime must be before endTime
| Date startTimePart = TimeUtil.makeDate(null, startTime); // sets date part to 1.1.1970
| Date endTimePart = TimeUtil.makeDate(null, endTime); // sets date part to 1.1.1970
| return (startTimePart.compareTo (endTimePart) <= 0);
| }
| }
| return true;
| }
|
| //Implemented by the interface
|
| /**
| * Compare this with another ScheduleEntry using the given Comparator
| * @param entry
| * @return 0 if equal, 1 if this is later, -1 if this is earlier
| *
| * @see net.uniopt.sys.IScheduleEntry#compareTo(net.uniopt.sys.IScheduleEntry, java.util.Comparator)
| */
| @Transient
| public int compareTo (IScheduleEntry entry, Comparator<IScheduleEntry> comparator) {
| return comparator.compare (this, entry);
| }
|
| /**
| * @see net.uniopt.sys.IScheduleEntry#getDow()
| */
| @Transient
| public int getDow() {
| return dow;
| }
|
| /**
| * @see net.uniopt.sys.IScheduleEntry#getEndDateTime()
| */
| @Transient
| public Date getEndDateTime () {
| return TimeUtil.combine (getEndDate(), getEndTime());
| }
|
| /**
| * @see net.uniopt.sys.IScheduleEntry#getStartDateTime()
| */
| @Transient
| public Date getStartDateTime () {
| return TimeUtil.combine (getStartDate(), getStartTime());
| }
|
| /**
| * @see net.uniopt.sys.IScheduleEntry#setDates(java.util.Date, java.util.Date)
| */
| @Transient
| public void setDates (Date startDate, Date endDate) throws VetoException {
| setValues(startDate, this.startTime, endDate, this.endTime);
| }
|
| /**
| * @see net.uniopt.sys.IScheduleEntry#setDow(int)
| */
| @Transient
| public void setDow (int i) {
| if (dow != i) {
| dow = i;
| if( schedule != null ) schedule.entryChanged (this);
| }
| }
|
| /**
| * Sets the end date/time to the given values.
| * If time is null, the value "23:59:59" is used.
| *
| * @see net.uniopt.sys.IScheduleEntry#setEnd(java.util.Date, java.util.Date)
| */
| @Transient
| public void setEnd (Date date, Date time) throws VetoException {
|
| if (time == null) time = TimeUtil.makeTime(23,59,59);
|
| if ( !isValidScheduleEntry( startDate, startTime, date, time ) )
| {
| throw new VetoException ("Schedule End cannot be before Schedule Begin.");
| }
|
| endDate = date;
| endTime = time;
|
| if( schedule != null ) schedule.entryChanged (this);
| }
|
| /**
| * @see net.uniopt.sys.IScheduleEntry#setSchedule(net.uniopt.sys.ISchedule)
| */
| @Transient
| public void setSchedule (ISchedule other) {
| if (other != null && !(other instanceof Schedule))
| throw new RuntimeException ("Cannot set instance of \""+other.getClass().getName()+"\" as parent of a " + getClass().getName()+".");
|
| if (other != schedule) {
| if (schedule != null)
| schedule.removeEntry (this);
| schedule = (Schedule)other;
| if (schedule != null)
| schedule.addEntry (this);
| }
| }
|
| /**
| * Sets the start date/time to the given values.
| * If time is null, the value "00:00:00" is used.
| *
| * @see net.uniopt.sys.IScheduleEntry#setStart(java.util.Date, java.util.Date)
| */
| @Transient
| public void setStart(Date date, Date time) throws VetoException {
|
| if (time == null) time = TimeUtil.makeTime(0,0,0);
|
| if ( !isValidScheduleEntry( date, time, endDate, endTime ) )
| {
| throw new VetoException ("Schedule End cannot be before Schedule Begin.");
| }
|
| startDate = date;
| startTime = time;
|
| if( schedule != null ) schedule.entryChanged (this);
| }
|
| /**
| * @see net.uniopt.sys.IScheduleEntry#setTimes(java.util.Date, java.util.Date)
| */
| @Transient
| public void setTimes (Date startTime, Date endTime) throws VetoException {
| setValues(this.startDate, startTime, this.endDate, endTime);
| }
|
| /**
| * @see net.uniopt.sys.IScheduleEntry#setValues(java.util.Date, java.util.Date, java.util.Date, java.util.Date)
| */
| @Transient
| public void setValues (Date startDate, Date startTime, Date endDate, Date endTime) throws VetoException {
| Date oldStartDate = this.startDate;
| Date oldStartTime = this.startTime;
| Date oldEndDate = this.endDate;
| Date oldEndTime = this.endTime;
|
| setEnd(null, null); // To bypass the validation
| setStart(startDate, startTime); // should always work now.
|
| try {
| setEnd(endDate, endTime); // This time a validation is done.
| } catch (VetoException xc) {
| this.startDate = oldStartDate;
| this.startTime = oldStartTime;
| this.endDate = oldEndDate;
| this.endTime = oldEndTime;
| throw xc;
| }
| if( schedule != null ) schedule.entryChanged (this);
| }
| }
|
|
|
the method which invokes the loading looks like this
public void test () {
| Query query = em.createQuery("SELECT s FROM Schedule s LEFT JOIN FETCH s.scheduleEntries ");
|
| try {
| Set<Tour> resultSet = new HashSet<Tour>(query.getResultList());
| Iterator<?> iter = resultSet.iterator();
| while (iter.hasNext()) {
| Schedule schedule = (Schedule) iter.next();
| System.out.println(schedule.getScheduleId() + " " + schedule.getScheduleEntries().size());
| }
| } catch (Exception ex) {
| ex.printStackTrace();
| }
| }
|
So I am really confused because it works on windows but not on my mac...
This can´t be the topic or?
Thanks for your help!
regards
markus
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4119750#4119750
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4119750
More information about the jboss-user
mailing list