我在多个网站上搜索过,找到了一些解决方案,但这并没有解决我的问题。有人可以帮我这个。
问题: - 无法从类型[java.lang.Object []]转换为类型
我已尝试如下预测,能够从数据库中检索数据,但列值未与数据成员正确关联。列值随机映射到成员。
例如: - 实际结果:
[{ ipaddress = 1, ipaddressvalue = 256,ipnetmask = 24,ipaddresspoolid = 1, unallocatedcount = 0,ipaddresspoolrangeid = 10.101。 10.0,版本 = 174393856}]
预期结果:
[{ ipaddress = 10.101.10.0, ipaddressvalue = 174393856,ipnetmask = 24,ipaddresspoolid = 1, unallocatedcount = 256,ipaddresspoolrangeid = 1,版本 = 0}]
我的实体类: -
@Entity
@Table(name = "IPADDRESSALLOCATION")
public class IPAddressAllocation {
@Id
@Column(name = "ADDRESSALLOCATIONID")
@NotNull
private int addressAllocationId;
@Column(name = "IPADDRESSPOOLRANGEID")
private int ipAddressPoolrangeId;
@Column(name = "IPADDRESS")
@NotNull
private String ipAddress;
@Column(name = "COUNT")
@NotNull
private int count;
@Column(name = "SERVICEIDENTIFIER")
@NotNull
private String serviceIdentifier;
@Column(name = "USERNAME")
@NotNull
private String userName;
@Column(name = "VERSION")
@NotNull
private int version;
@Column(name = "IPADDRESSVALUE")
@NotNull
private long ipAddressValue;
//setter/getters
} // end of Entity
我的存储库界面: -
选择查询连接多个表[3个表]并根据给定的条件提取少量列。
public interface PoolRepository extends JpaRepository<IPAddressAllocation, String> {
@Query(value = "SELECT r.ipaddresspoolrangeid , r.ipaddresspoolid, r.ipaddress,"
+ "r.unallocatedcount, r.ipnetmask, r.version, r.ipaddressvalue from ippool_service_assignment s,"
+ "ipaddressPool p, ipaddress_pool_range r where p.customerid = :cidn and "
+ "p.customernetwork = :networkId and s.serviceidentifier =:serviceIdentifier and "
+ "s.ipaddresspoolid = p.ipaddresspoolid and p.ipaddresspoolid = r.ipaddresspoolid and "
+ "((r.ipaddressvalue <=:firstIpAddress) and "
+ "((r.ipaddressvalue + power(2, 32-(r.ipnetmask))-1) >=:firstIpAddress)"
+ " or ( r.ipaddressvalue <=:lastIpAddress ) and "
+ "((r.ipaddressvalue + power(2, 32-(r.ipnetmask))-1) >=:firstIpAddress ))"
+ " Order by p.poolname, r.ipaddressvalue", nativeQuery = true)
List<IPAddressPoolAllocations> fetchIpPoolDetails(@Param("cidn") final String cidn,
@Param("networkId") final String networkId, @Param("serviceIdentifier") final String serviceIdentifier,
@Param("firstIpAddress") final long firstIpAddress, @Param("lastIpAddress") final long lastIpAddress);
static interface IPAddressPoolAllocations {
int getIpAddressPoolrangeId();
int getIpaddresspoolid();
String getIpAddress();
String getUnallocatedcount();
String getIpnetmask();
int getVersion();
long getIpAddressValue();
}
} //end of interface repository
我的ServiceImpl图层: -
@Autowired
private PoolRepository repository;
List<IPAddressPoolAllocations> ipAddressPoolAllocationList = repository.fetchIpPoolDetails(
String.valueOf(ipAllocation.getCidn()), ipAllocation.getCustomerNetworkId(), ipAllocation.getServiceIdentifier(), Long.parseLong(sfirstIpAddress),
Long.parseLong(slastIpAddress));
不确定我在这里做错了什么。